shell脚本,检查给出的字符串是否为回文

[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脚本,检查给出的字符串是否为回文的更多相关文章
- 用递归方法判断字符串是否是回文(Recursion Palindrome Python)
所谓回文字符串,就是一个字符串从左到右读和从右到左读是完全一样的.比如:"level" .“aaabbaaa”. "madam"."radar&quo ...
- [LeetCode]Palindrome Partitioning 找出所有可能的组合回文
给定一个字符串,切割字符串,这样每个子字符串是一个回文字符串. 要找出所有可能的组合. 办法:暴力搜索+回溯 class Solution { public: int *b,n; vector< ...
- Manacher算法讲解——字符串最长回文子串
引 入 引入 引入 Manachar算法主要是处理字符串中关于回文串的问题的,这没什么好说的. M a n a c h e r 算 法 Manacher算法 Manacher算法 朴素 求一个字符串中 ...
- javascript判断给定字符串是否是回文
//判断给定字符串是否是回文 function isPalindrome(word) { var s = new Stack(); for (var i = 0 ...
- AC日记——判断字符串是否为回文 openjudge 1.7 33
33:判断字符串是否为回文 总时间限制: 1000ms 内存限制: 65536kB 描述 输入一个字符串,输出该字符串是否回文.回文是指顺读和倒读都一样的字符串. 输入 输入为一行字符串(字符串中 ...
- C实例--推断一个字符串是否是回文数
回文是指顺读和反读内容均同样的字符串.比如"121","ABBA","X"等. 本实例将编写函数推断字符串是否是回文. 引入两个指针变量,開 ...
- C#进行回文检测,判断字符串是否是回文的代码
下面代码内容是关于C#进行回文检测,判断字符串是否是回文的代码,应该是对各位朋友有些好处. Console.WriteLine("算法1:请输入一个字符串!");string st ...
- [leetcode]131. Palindrome Partitioning字符串分割成回文子串
Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...
- YTUOJ-推断字符串是否为回文
题目描写叙述 编敲代码,推断输入的一个字符串是否为回文.若是则输出"Yes",否则输出"No".所谓回文是指順读和倒读都是一样的字符串. 输入 输出 例子输入 ...
随机推荐
- bzoj 4873: [Shoi2017]寿司餐厅【最大权闭合子图】
有正负收益,考虑最小割 因为有依赖关系,所以考虑最大权闭合子图 首先对每个d[i][j]建个点,正权连(s,id[i][j],d[i][j])并加到ans上,负权连(id[i][j],t,-d[i][ ...
- [Xcode 实际操作]九、实用进阶-(21)使用“调试视图”查看各界面元素的层次顺序
目录:[Swift]Xcode实际操作 本文将演示如何在程序运行期间,查看模拟器各界面元素的层次顺序. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import ...
- chmod 详解
http://man.linuxde.net/chmod chmod u+x,g+w f01 //为文件f01设置自己可以执行,组员可以写入的权限 chmod u=rwx,g=rw,o=r f01 c ...
- 01 | VIM基础攻略
启动 vim 后,vim 处于 normal 模式. Step One: "i" -> insert 模式, ESC -> normal 模式: "x&quo ...
- SpringMvc源码入门
servlet httpServletRequest httpServlet
- PostgreSQL - 怎么转换数据类型
前言 对于select 233;这个sql,得到的结果是int4类型,如果我们希望将结果转换成其他的数据类型,有以下方法(下边的{数据类型}表示占位符,要替换成数据库中的某一种数据类型): 方法一:使 ...
- JToken和JObject有什么区别
JObject 用于操作JSON对象JArray 用语操作JSON数组JValue 表示数组中的值JProperty 表示对象中的属性,以"key/value"形式JT ...
- SqlServer存储过程调用接口
因项目需求.需实现新增数据->触发器->存储过程->调用接口. https://blog.csdn.net/u010485134/article/details/58603370 另 ...
- PHP之session
p:first-child, #write > ul:first-child, #write > ol:first-child, #write > pre:first-child, ...
- HTML 5的革新——语义化标签(二)
HTML 5的革新之一:语义化标签二文本元素标签.分组元素标签. HTML 5的革新——语义化标签(一)中介绍了一些HTML5新加的一些节元素,一张页面中结构元素构成网页大体,但是也需要其他内容来填充 ...