Palindromes _easy version
Palindromes _easy version
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 28818 Accepted Submission(s): 17516
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
1 #include<stdio.h> 2 #include<string.h> 3 int main (void) 4 { 5 char a[400], temp[200]; 6 int i, j, k, n, len; 7 while(scanf("%d\n", &n) == 1){ 8 for(i = 0; i < n; i++){ 9 gets(a); 10 int count = 0; 11 for(j = 0, k = strlen(a)-1; j < strlen(a)/2; j++, k--) 12 if(a[j] != a[k]) 13 count = 1; 14 if(count == 1) 15 printf("no\n"); 16 else 17 printf("yes\n"); 18 } 19 } 20 return 0; 21 }