写一个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
答案
暂无答案

题目信息

题号:7165
题型:简答题
难度:普通