Skip to content

Commit

Permalink
leetcode: Add 0194
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Jun 2, 2024
1 parent f97a602 commit a0f5148
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/leetcode/0194.transpose-file/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "lc-0194-transpose-file"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
3 changes: 3 additions & 0 deletions src/leetcode/0194.transpose-file/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name age
alice 21
ryan 30
1 change: 1 addition & 0 deletions src/leetcode/0194.transpose-file/file0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a
4 changes: 4 additions & 0 deletions src/leetcode/0194.transpose-file/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#

[问题描述](../problems/)
41 changes: 41 additions & 0 deletions src/leetcode/0194.transpose-file/solve.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

solution1() {
names=()
ages=()
while read line; do
name=$(echo "${line}" | grep -oP '\w+\s')
age=$(echo "${line}" | grep -oP '\s+\w+')
names+=("$name")
ages+=("$age")
done

for name in ${names[@]}; do
echo -n "${name} "
done
echo ""

for age in ${ages[@]}; do
echo -n "${age} "
done
echo ""
}

solution2() {
awk '{print}' ORS=' '
}

solution3() {
local columns=$(head -n1 "$1" | wc -w)
for column_num in $(seq 1 "${columns}"); do
#cat "$1" | cut -d' ' -f "${column_num}" | tr '\n' ' '
#cat "$1" | cut -d' ' -f "${column_num}" | awk '{print}' ORS=' '
#cat "$1" | cut -d' ' -f "${column_num}" | paste -s -d ' '
cat "$1" | cut -d' ' -f "${column_num}" | xargs
done
}

#solution1 < file.txt
#solution2 < file.txt
solution3 file.txt
solution3 file0.txt
27 changes: 27 additions & 0 deletions src/leetcode/0194.transpose-file/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2024 Xu Shaohua <[email protected]>. All rights reserved.
// Use of this source is governed by General Public License that can be found
// in the LICENSE file.

pub fn solution1() {
todo!();
}

pub type SolutionFn = fn();

fn check_solution(_func: SolutionFn) {
todo!();
}

fn main() {
check_solution(solution1);
}

#[cfg(test)]
mod tests {
use super::{check_solution, solution1};

#[test]
fn test_solution1() {
check_solution(solution1);
}
}
1 change: 1 addition & 0 deletions src/leetcode/0194.transpose-file/xaa
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a b

0 comments on commit a0f5148

Please sign in to comment.