Palindromes _easy version
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 27492 Accepted Submission(s):
16699
Problem Description
“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”。
Input
输入包含多个测试实例,输入数据的第一行是一个正整数n,表示测试实例的个数,后面紧跟着是n个字符串。
Output
如果一个字符串是回文串,则输出"yes",否则输出"no".
Sample Input
4
level
abcde
noon
haha
Sample Output
yes
no
yes
no
Author
lcy
Source
Recommend
题意:判断字符串是否为回文串
1 #include <stdio.h> 2 #include <string.h> 3 char str[1010] ; 4 int main() 5 { 6 int n ; 7 scanf("%d", &n) ; 8 while(n--) 9 { 10 getchar() ; 11 int len, i, j ; 12 scanf("%s", str); 13 len = strlen(str) ; 14 for(i=0,j=len-1; i<len; i++,j--) 15 { 16 //printf("%c %c ",str[i], str[j]) ; 17 if(str[i] != str[j]) 18 break ; 19 } 20 if(i == len) 21 printf("yes ") ; 22 else 23 printf("no ") ; 24 } 25 return 0 ; 26 }