判断回文字符串
来源:互联网 发布:扣字刷屏软件手机版 编辑:程序博客网 时间:2024/05/19 14:56
“回文”就是从左往右看和从右往左看是一样的字符串。
1.判断回文字符串
1) 递归,回文字符串取出首尾的两个字符剩下的依然是回文串,当个数为奇数时最后剩下一个字符,当个数位偶数时剩下零个字符,一个或零个必然是回文串。
<pre name="code" class="cpp">#include <iostream>using namespace std;#include <cstring>bool isPalindrome(int begin,int end,char str[],int length){ if(length==0||length==1) return true; if(str[begin]!=str[end]) return false; return isPalindrome(begin+1,end-1,str,length-2);}int main(){ char str[100]; cin.getline(str,100); if(isPalindrome(0,strlen(str)-1,str,strlen(str))) cout<<"yes"<<endl; else cout<<"no"<<endl; return 0; }
2) 利用回文串首尾字符一样。
<pre name="code" class="cpp">#include <iostream>using namespace std;#include <cstring>bool isPalindrome(char str[],int length){ for(int i=0;i<length/2;i++) if(str[i]!=str[length-1-i]) return false; return true;}int main(){ char str[100]; cin.getline(str,100); if(isPalindrome(str,strlen(str))) cout<<"yes"<<endl; else cout<<"no"<<endl; return 0;}
0 0
- 回文数回文字符串判断
- 字符串回文判断
- 判断字符串是否回文
- 判断字符串是不是回文
- 判断回文字符串
- 判断字符串是否回文
- 判断回文字符串
- 判断回文字符串
- 判断字符串是否回文
- 判断回文字符串
- 回文字符串的判断
- 判断回文字符串.
- 字符串回文判断
- 判断回文字符串
- 判断字符串是否回文
- 判断回文字符串
- 整理判断回文字符串
- 回文字符串判断
- 编写java无脚本的JSP页面
- C/C++ typedef用法
- pthreads : pthread_cond_signal() from within critical section
- matlab神经网络newff函数的用法
- CodeBlocks 安装与配置
- 判断回文字符串
- 2016ccpc杭州赛 hdu 5938 F.Four Operations
- Android 高仿 QQ5.0 侧滑菜单效果 自定义控件来袭
- 2016年上半年总结
- android 使用百度地图sdk
- 正则表达式
- Vm Funsion使用Fn快捷键
- 旋转数组中最小数
- bestcode Fxx and string