diff --git a/src/leetcode/0194.transpose-file/Cargo.toml b/src/leetcode/0194.transpose-file/Cargo.toml new file mode 100644 index 000000000..524f18b6c --- /dev/null +++ b/src/leetcode/0194.transpose-file/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "lc-0194-transpose-file" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] diff --git a/src/leetcode/0194.transpose-file/file.txt b/src/leetcode/0194.transpose-file/file.txt new file mode 100644 index 000000000..c2d39ae0e --- /dev/null +++ b/src/leetcode/0194.transpose-file/file.txt @@ -0,0 +1,3 @@ +name age +alice 21 +ryan 30 diff --git a/src/leetcode/0194.transpose-file/file0.txt b/src/leetcode/0194.transpose-file/file0.txt new file mode 100644 index 000000000..789819226 --- /dev/null +++ b/src/leetcode/0194.transpose-file/file0.txt @@ -0,0 +1 @@ +a diff --git a/src/leetcode/0194.transpose-file/index.md b/src/leetcode/0194.transpose-file/index.md new file mode 100644 index 000000000..77a618ba8 --- /dev/null +++ b/src/leetcode/0194.transpose-file/index.md @@ -0,0 +1,4 @@ + +# + +[问题描述](../problems/) diff --git a/src/leetcode/0194.transpose-file/solve.sh b/src/leetcode/0194.transpose-file/solve.sh new file mode 100755 index 000000000..2d7ff4ffd --- /dev/null +++ b/src/leetcode/0194.transpose-file/solve.sh @@ -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 diff --git a/src/leetcode/0194.transpose-file/src/main.rs b/src/leetcode/0194.transpose-file/src/main.rs new file mode 100644 index 000000000..9edcfeb7d --- /dev/null +++ b/src/leetcode/0194.transpose-file/src/main.rs @@ -0,0 +1,27 @@ +// Copyright (c) 2024 Xu Shaohua . 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); + } +} diff --git a/src/leetcode/0194.transpose-file/xaa b/src/leetcode/0194.transpose-file/xaa new file mode 100644 index 000000000..b2901ea97 --- /dev/null +++ b/src/leetcode/0194.transpose-file/xaa @@ -0,0 +1 @@ +a b