法一:
#include<iostream> #include<string> using namespace std; int main() { int i,j,n,m,x=0; char s[120]; cin>>n; while(n--) { cin>>s; m=strlen(s); for(i=0,j=m-1;i<m,j>=0;i++,j--) { if(s[i]==s[j]) x++; } if(x==m) cout<<"yes"<<endl; else cout<<"no"<<endl; x=0; } return 0;}
法二:
#include<iostream> #include<string> using namespace std; int main() { int n,i,m,flag=1; char a[100],b[100]; cin>>n; while(n--) { cin>>a; m=strlen(a); for(i=0;i<m;i++) { b[i]=a[m-i-1]; if(a[i]!=b[i]) flag=0; } if(flag) cout<<"yes"<<endl; else cout<<"no"<<endl; flag=1; } return 0; }