简要题意:
判断一串字符是否为“回文串”字符。“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”。
解题思路:
定义字符数组,输入一串字符,判断字符第i和第n-i项是否相同。
细节处理:
- strlen()函数定义在<cstring>中
源代码:
#include<iostream>
#include<cstring>
using namespace std;
const int size=15;
char a[size];
int main()
{
int n;
while(cin>>n)
{
for(int m=0;m<n;m++)
{
int k=0;
cin>>a;
for(int i=0,j=strlen(a);i<strlen(a)/2;i++,j--)
{
if(a[i]!=a[j-1]) k=1;
}
if(k==0) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
}
return 0;
}