[root@localhost wyb]# cat .sh
#!/bin/bash
#检查给出的字符串是否为回文 read -p "Please input a String:" number
[ -z $number ] && echo "input nothing " && exit len=${#number}
count=$((len/)) for i in `seq $count`
do
lasti=$((len-i+))
first=`echo $number|cut -c $i`
two=`echo $number|cut -c $lasti` [[ "$first" != "$two" ]] && echo no && exit done
echo yes
[root@localhost wyb]# bash .sh
Please input a String:
yes
[root@localhost wyb]# bash .sh
Please input a String:
yes
[root@localhost wyb]# bash .sh
Please input a String:
no
[root@localhost wyb]# bash .sh
Please input a String:
yes
[root@localhost wyb]#
用rev来检查是不是回文
[root@localhost wyb]# cat rev12321.sh
#!/bin/bash
#检查给出的字符串是否为回文
read -p "Please input a String:" number
[ -z $number ] && echo "input nothing " && exit a1=`echo $number|tac`
b2=`echo $number|rev`
[[ "$a1" != "$b2" ]] && echo no || echo yes [root@localhost wyb]# bash rev12321.sh
Please input a String:
no
[root@localhost wyb]# bash rev12321.sh
Please input a String:
yes
[root@localhost wyb]# bash rev12321.sh
Please input a String:
no
[root@localhost wyb]# bash rev12321.sh
Please input a String:
yes
[root@localhost wyb]#

[root@localhost wyb]# cat rev.sh
#!/bin/bash
#检查给出的字符串是否为回文 read -p "Please input a String:" number
[ -z $number ] && echo "input nothing " && exit number2=`echo $number|rev` [[ "$number2" = "$number" ]] && echo yes || echo no
[root@localhost wyb]# bash rev.sh
Please input a String:
yes
[root@localhost wyb]# bash rev.sh
Please input a String:
no
[root@localhost wyb]# bash rev.sh
Please input a String:
yes
[root@localhost wyb]#
 


shell脚本,检查给出的字符串是否为回文的更多相关文章

  1. 用递归方法判断字符串是否是回文(Recursion Palindrome Python)

    所谓回文字符串,就是一个字符串从左到右读和从右到左读是完全一样的.比如:"level" .“aaabbaaa”. "madam"."radar&quo ...

  2. [LeetCode]Palindrome Partitioning 找出所有可能的组合回文

    给定一个字符串,切割字符串,这样每个子字符串是一个回文字符串. 要找出所有可能的组合. 办法:暴力搜索+回溯 class Solution { public: int *b,n; vector< ...

  3. Manacher算法讲解——字符串最长回文子串

    引 入 引入 引入 Manachar算法主要是处理字符串中关于回文串的问题的,这没什么好说的. M a n a c h e r 算 法 Manacher算法 Manacher算法 朴素 求一个字符串中 ...

  4. javascript判断给定字符串是否是回文

    //判断给定字符串是否是回文     function isPalindrome(word) {         var s = new Stack();         for (var i = 0 ...

  5. AC日记——判断字符串是否为回文 openjudge 1.7 33

    33:判断字符串是否为回文 总时间限制:  1000ms 内存限制:  65536kB 描述 输入一个字符串,输出该字符串是否回文.回文是指顺读和倒读都一样的字符串. 输入 输入为一行字符串(字符串中 ...

  6. C实例--推断一个字符串是否是回文数

    回文是指顺读和反读内容均同样的字符串.比如"121","ABBA","X"等. 本实例将编写函数推断字符串是否是回文. 引入两个指针变量,開 ...

  7. C#进行回文检测,判断字符串是否是回文的代码

    下面代码内容是关于C#进行回文检测,判断字符串是否是回文的代码,应该是对各位朋友有些好处. Console.WriteLine("算法1:请输入一个字符串!");string st ...

  8. [leetcode]131. Palindrome Partitioning字符串分割成回文子串

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  9. YTUOJ-推断字符串是否为回文

    题目描写叙述 编敲代码,推断输入的一个字符串是否为回文.若是则输出"Yes",否则输出"No".所谓回文是指順读和倒读都是一样的字符串. 输入 输出 例子输入 ...

随机推荐

  1. 浅谈C++中内存泄漏的检测

    首先我们需要知道程序有没有内存泄露,然后定位到底是哪行代码出现内存泄露了,这样才能将其修复.最简单的方法当然是借助于专业的检测工具,比较有名如BoundsCheck,功能非常强大,相信做C++开发的人 ...

  2. 51nod1352(exgcd)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1352 题意:中文题诶- 思路:exgcd 显然题目可以描述为: ...

  3. IT兄弟连 JavaWeb教程 JSP经典面试题

    1.JSP标准提供了三种独立的向JSP添加Java代码的技术,请列举. <% %>JSP程序代码块,内部可以直接嵌入Java代码. <%! %>JSP声明区,内部可以声明变量和 ...

  4. day04 Calendar类

  5. E: 软件包 ffmpeg 没有可供安装的候选者

    问题:在DSO安装依赖项ffmpeg时遇到“E: 软件包 ffmpeg 没有可供安装的候选者”这一问题. 解决:在Ubuntu上gstreamer0.10-ffmpeg属于额外的版权受限程序,gstr ...

  6. VLAN-6-VLAN Trunk协议(VTP)

    VTP能够将VLAN配置信息通告给邻居交换机,这样做可以使工程师只在一台交换机上配置VLAN,同一个VTP域中的所有其他交换机动态学习这些VLAN信息.VTP通告VLAN ID.VLAN 名称和 VL ...

  7. python的正则表达式支持(链接)

    http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html

  8. PHP之session

    p:first-child, #write > ul:first-child, #write > ol:first-child, #write > pre:first-child, ...

  9. B.选点

    链接:https://ac.nowcoder.com/acm/contest/368/B 题意: 有一棵n个节点的二叉树,1为根节点,每个节点有一个值wi.现在要选出尽量多的点. 对于任意一棵子树,都 ...

  10. bzoj 4597||洛谷P4340 [Shoi2016]随机序列

    https://www.lydsy.com/JudgeOnline/problem.php?id=4597 https://www.luogu.org/problemnew/show/P4340 妄图 ...