描述
Palindromes are strings that read the same both forwards and backwards. `Eye' is one such example (ignoring case). In this problem, you get to write a program to determine if a given word is a palindrome or not.
输入
Each line of input contains one word with no embedded spaces. Each word will have only alphabetic characters (either upper or lower case).
输出
For each line of input, output either `yes' if the word is a palindrome or `no' otherwise. Don't print the quotes. Case should be ignored when checking the words.
样例输入
eyE
laLAlal
Foof
foobar
样例输出
yes
yes
yes
no
1 #include<stdio.h> 2 #include<string.h> 3 #include<ctype.h> 4 #include<math.h> 5 6 char s[65536]; 7 8 void solve() 9 { 10 int i,len; 11 while(gets(s)) 12 { 13 len=strlen(s); 14 for(i=0; i<len/2; i++) 15 { 16 if(tolower(s[i])!=tolower(s[len-1-i])) 17 break; 18 } 19 if(i==len/2) 20 printf("yes\n"); 21 else 22 printf("no\n"); 23 } 24 } 25 26 int main() 27 { 28 solve(s); 29 getchar(); 30 getchar(); 31 return 0; 32 }
作者:xueda120
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.