回文字符串

题目链接:https://www.nowcoder.com/practice/df00c27320b24278b9c25f6bb1e2f3b8?tpId=40&tqId=21559&tPage=12&rp=3&ru=%2Fta%2Fkaoyan&qru=%2Fta%2Fkaoyan%2Fquestion-ranking

题目描述

给出一个长度不超过1000的字符串,判断它是不是回文(顺读,逆读均相同)的。

输入描述:

输入包括一行字符串,其长度不超过1000。

输出描述:

可能有多组测试数据,对于每组数据,如果是回文字符串则输出"Yes!”,否则输出"No!"。
示例1

输入

hellolleh
helloworld

输出

Yes!
No!
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 #include <stack>
 5 #include <string>
 6 #include <cstring>
 7 #include <cmath>
 8 #include <cstdio>
 9 using namespace std;
10 char a[1010];
11 int main()
12 {
13     while(scanf("%s",a)!=EOF){
14         int len=strlen(a);
15         int flag=1;
16         for(int i=0;i<=len/2;i++){
17             if(a[i]!=a[len-i-1]){
18                 flag=0;
19                 break;
20             }
21         }
22         if(flag) cout<<"Yes!"<<endl;
23         else cout<<"No!"<<endl;
24     }
25     return 0;
26 }
原文地址:https://www.cnblogs.com/wydxry/p/8075522.html