回文串
来源:互联网 发布:mac机中钉钉无法登陆 编辑:程序博客网 时间:2024/05/02 00:23
题目描述
给定一个字符串,问是否能通过添加一个字母将其变为回文串。
IDEA
若果这个字符串能够通过添加一个字符变为回文,则其也可以通过删除一个字符变为回文,删除一个字符:
str.erase(i,1);
CODE
#include<iostream>#include<fstream> #include<string>using namespace std;int isPalindrome(string str){for(int i=0;i<str.length();i++){if(str[i]!=str[str.length()-1-i]){return 0;}}return 1;}int main(){#ifndef ONLINE_JUDGEfreopen("input.txt","r",stdin);#endif string s; while(cin>>s){ int i=0; for(;i<s.length();i++){ string str=s; str.erase(i,1); //cout<<str<<endl; if(isPalindrome(str)){ cout<<"YES"<<endl; break;}}if(i==s.length()){cout<<"NO"<<endl;}} return 0;}
0 0
- 回文数&&回文串
- 回文串
- 回文串
- 回文串
- 回文串
- 回文串
- 回文串
- 回文串
- 回文串
- 回文串
- 回文串
- 回文串
- **回文串
- 回文串
- 回文串
- 回文串
- 回文串
- 回文串
- yii2 直接输出model的(active record)sql语句
- linux 修改时间
- Android中IPC的几种方式详细分析与优缺点分析
- index.html:41 XMLHttpRequest cannot load file:///E:/myproject/datas/index.txt. Cross origin requests
- python-django-----mac终端常用命令
- 回文串
- 20170315
- Python3 cookbook学习笔记-数据结构与算法1
- 字符大小转化
- PHP empty函数测试对象使用魔术方法获取的属性
- android 绘制圆形的ImageView
- 网速前端计算&系统探测
- 文章标题
- 最全C#中ToString()用法大全