Palindromes _easy version
Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 47 Solved: 27
[ Submit][ Status][ Web Board]
Description
“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”。
Input
输入包含多个测试实例,输入数据的第一行是一个正整数n,表示测试实例的个数,后面紧跟着是n个字符串,每个字符串的长度不超过500。
Output
如果一个字符串是回文串,则输出"yes",否则输出"no".
Sample Input
4
level
abcde
noon
haha
Sample Output
yes
no
yes
no
HINT
1 #include <iostream> 2 #include <stdio.h> 3 using namespace std; 4 5 int main() 6 { 7 int n; 8 cin>>n; 9 getchar(); 10 while(n--){ 11 char s[501]; 12 cin.getline(s,500,'\n'); 13 int i,l; 14 for(l=0;s[l]!='\0';l++); 15 for(i=0;i<l;i++) 16 if(s[i]!=s[l-i-1]) 17 break; 18 if(i==l) 19 cout<<"yes"<<endl; 20 else 21 cout<<"no"<<endl; 22 } 23 return 0; 24 }
Freecode : www.cnblogs.com/yym2013