1806: 回文字符串

题目描述

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

输入

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

输出

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

样例输入

hellolleh
helloworld

样例输出

Yes!
No!

 1 #include<stdio.h>
 2 #include<string.h>
 3 bool p(char a[]){
 4     int len=strlen(a);
 5     for(int i=0;i<len/2;i++){
 6         if(a[i]!=a[len-i-1]){
 7             printf("No!\n");
 8             return false;
 9         }
10     }
11     printf("Yes!\n");
12     return true;
13 }
14 int main(){
15     char str[1000];
16     while(scanf("%s",str)!=EOF){
17         p(str);
18         memset(str,'\0',sizeof(str));
19     }
20     
21     return 0;
22 }
 

猜你喜欢

转载自www.cnblogs.com/mist2019/p/10340111.html
今日推荐