题目描述
输入一个字符串,输出该字符串是否回文。回文是指顺读和倒读都一样的字符串。
输入格式
输入一行字符串,长度小于 100 100 100。
输出格式
如果字符串是回文,输出 yes;否则,输出 no。
样例 #1
样例输入 #1
abcdedcba
样例输出 #1
yes
代码
#include <bits/stdc++.h>
using namespace std;
bool check(string s,int left,int right)
{
if(s[left]!=s[right])
{
return false;
}
if(left>=right)
{
return true;
}
return check(s,left+1,right-1);
}
int main()
{
string s;
getline(cin,s);
if(check(s,0,s.length()-1))
{
cout<<"yes";
}
else
{
cout<<"no";
}
return 0;
}
2249



被折叠的 条评论
为什么被折叠?



