原題地址:牛客網
題目描述:
給出一個長度不超過1000的字符串,判斷它是不是迴文(順讀,逆讀均相同)的。
輸入描述:
輸入包括一行字符串,其長度不超過1000。
輸出描述:
可能有多組測試數據,對於每組數據,如果是迴文字符串則輸出"Yes!”,否則輸出"No!"。
示例1
輸入
hellolleh helloworld
輸出
Yes! No!
分析:
就前後比較就行。簽到題。
代碼:
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string a;
while(cin>>a)
{
int s=0,l=a.length()-1;
int k=0;
while(s<l)
{
if(a[s]!=a[l]){k=1;break;}
s++;
l--;
}
if(k==0)cout<<"Yes!"<<endl;
else cout<<"No!"<<endl;
}
return 0;
}
2020.4.11