[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++函数返回值与引用

    对于函数的返回值,看似简单,但并非如此,比如: int func(int a);该函数会返回一个int型,如果进行一个调用int result=func(3);会发生什么情况? 首先,func将返回值 ...

  2. P3803 【模板】多项式乘法(NTT)

    传送门 NTT好像是比FFT快了不少 然而感觉不是很看得懂……主要是点值转化为系数表示那里…… upd:大概已经搞明白是个什么玩意儿了……吧…… //minamoto #include<bits ...

  3. ubuntu 14.04 源码编译postgresql

    环境 ubuntu 14.04 桌面版 postgresql 源码下载链接,本教程是使用postgresql 9.3.4 进行编译的 http://www.postgresql.org/ftp/sou ...

  4. SVN有任何胜过git的地方吗?

    SVN有任何胜过git的地方吗? 好的技术问题通常会引出技术专家们依据经验得出的深层次的观点.但对于这样的问题的答案也很容易演变成完全基于个人喜好的情绪倾泄,而不是根据事实.标准和具体的专业知识.就比 ...

  5. 描述符__get__,__set__,__delete__和析构方法__del__

    描述符__get__,__set__,__delete__ 1.描述符是什么:描述符本质就是一个新式类,在这个新式类中,至少实现了__get__(),__set__(),__delete__()中的一 ...

  6. with rollup

    实验吧的一道ctf题,这两天无聊,做做ctf题.在实验吧被一道也题卡了好久. 页面很简单就是一个登陆页面,按照之前的经验觉得应该是注入吧.再看题猜测应该是绕waf之类的. 查看页面源码找到了提供的源代 ...

  7. FFT与NTT的模板

    网上相关博客不少,这里给自己留个带点注释的模板,以后要是忘了作提醒用. 以洛谷3803多项式乘法裸题为例. FFT: #include <cstdio> #include <cmat ...

  8. typedef与复杂声明

    参考 [1] http://www.cnblogs.com/bakari/archive/2012/08/28/2659889.html [2]<C专家编程> [3 ]http://www ...

  9. ecshop的商品列表输出中多出一条空记录

    这个是ECSHOP的一个BUG, 在模板中显示商品列表的位置,加一句{if $goods}判断商品存在才显示: {foreach from=$goods_list item=goods} {if $g ...

  10. #52. 【UR #4】元旦激光炮 (交互式题)

    链接:http://uoj.ac/problem/52 刚刚越过绝境长城,只见天空中出现了炫目的光芒 —— 圣诞老人出现了. 元旦三侠立刻进入战斗.生蛋侠.圆蛋侠和零蛋侠分别有 na,nb,ncna, ...