原创作品 转载请注明出处http://blog.csdn.net/always2015/article/details/45534211
简单题,我的AC代码如下:
#include <iostream>
#include<string>
using namespace std;
int main()
{
int n,lenght,flag=0;
string input_str;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>input_str;
lenght=input_str.size();
for(int j=0; j<lenght; j++)
{
//将字符串前后字符进行比较相等则标志位加1
if(input_str[j]==input_str[lenght-j-1]&&j<=(lenght-1-j))
{
++flag;
}
}
//当字符串的长度为奇数时候且是该字符串是回文串,标志位是字符串长度一半加1
if(lenght%2!=0)
{
if(flag==(lenght/2+1))
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
else
{
if(flag==(lenght/2))
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
flag=0;
}
return 0;
}