SHELL20. 打印只有一个数字的行
描述
haha12abcd77
12ab
Bash 解法, 执行用时: 3ms, 内存消耗: 412KB, 提交时间: 2022-01-06
while read line do count=0 for (( i=0;i<${#line};i++ )) do if [[ ${line:$i:1} =~ [0-9] ]] then ((count++)) fi done if [ $count -eq 1 ] then echo $line fi done < nowcoder.txt
Bash 解法, 执行用时: 3ms, 内存消耗: 412KB, 提交时间: 2021-11-25
while read line do count=0 for ((i=0;i<${#line};i++)) do [[ ${line:i:1} =~ [0-9] ]] && ((count++)) done if [ $count -eq 1 ];then printf "$line\n" fi done < nowcoder.txt
Bash 解法, 执行用时: 3ms, 内存消耗: 416KB, 提交时间: 2022-01-15
while read line do let count=0 for (( i = 0; i < ${#line}; i++)) do if [[ ${line:i:1} =~ [0-9] ]]; then count=$(($count+1)) fi done if [ $count -eq 1 ];then printf "$line\n" fi done < nowcoder.txt
Bash 解法, 执行用时: 3ms, 内存消耗: 420KB, 提交时间: 2022-02-26
while read line;do count=0 for ((i=0;i<=${#line};i++));do if [[ ${line:$i:1} =~ [0-9] ]];then ((count++)) fi done if [[ $count -eq 1 ]];then echo $line fi done<nowcoder.txt
Bash 解法, 执行用时: 3ms, 内存消耗: 420KB, 提交时间: 2021-12-20
while read line do let count=0; for(( i = 0; i < ${#line}; i++)) do [[ ${line:i:1} =~ [0-9] ]] && ((count++)) done if [[ $count == 1 ]] then printf "$line \n" fi done < nowcoder.txt