写一个shell 脚本,检查给出的串是否为回文(pal
写一个shell 脚本,检查给出的串是否为回文(palindrome)。
参考程序:
#! /bin/bashecho "Enter string" read str len=`echo $str | wc -c` len=`expr $len - 1` l=`expr $len / 2` ctr=1 flag=0 while test $ctr -le $l do a=`echo $str | cut -c$ctr` b=`echo $str | cut -c$len` if test $a -ne $b then flag=1 break fi ctr=`expr $ctr + 1` len=`expr $len - 1` done if test $flag -eq 0 then echo "String is palindrome" else echo "String not a palindrome" fi
答案
暂无答案