leetcod_194_transpose_file
来源:互联网 发布:淘宝发表论文靠谱吗 编辑:程序博客网 时间:2024/05/21 19:30
方法效率不高,不过也算一次通过。
#!/bin/bashcc=0rc=0wc=0declare -a wordswhile read -r linedo let rc+=1 for word in $line; do words[wc]=$word let wc+=1 donedone <file.txtlet -i cc=wc/rcfor ((i=0; i<cc; i++))do line='' for((j=0; j<rc; j++)) do if ((j!=0)); then line+=' ';fi line+=${words[j*cc+i]}; done echo $linedone
0 0