7-1 判断回文字符串 (10分)
输入一个字符串,判断该字符串是否为回文。回文就是字符串中心对称,从左向右读和从右向左读的内容是一样的。
输入格式:
输入在一行中给出一个不超过80个字符长度的、以回车结束的非空字符串。
输出格式:
输出在第1行中输出字符串。如果它是回文字符串,在第2行中输出Yes,否则输出No。
输入样例1:
level
输出样例1:
level
Yes
输入样例2:
1 + 2 = 2 + 1 =
输出样例2:
1 + 2 = 2 + 1 =
No
代码展示:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
void check(string s)
{
bool flag = true;
for(int i=0;i<s.size();i++)
{
if(s[i]!=s[s.size()-i-1])
flag = false;
}
if(flag)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
int main()
{
string s;
getline(cin,s);
cout<<s<<endl;
check(s);
return 0;
}