Codeforces 505A Mr. Kitayuta's Gift
思路1: 字符串的长度一共是10,可以从'a'到'z' ,每一个位置添加后,尝试一遍
思路2: 从每个位置删除该字符,看剩余字符串是否构成字符串,如果构成字符串,则在对应位置添加该字符
细节注意:i在0到len/2-1 和len/2+len-1处理方式不同
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string temp,u,v;
string ans,t;
bool flag = false;
cin>>temp;
for ( int i=0; i<temp.length(); i++ ) {
t = temp.substr(i,1);
u = temp.substr(0,i) + temp.substr(i+1,temp.length()-i-1);
v = u;
reverse( v.begin(),v.end() );
if ( u==v ) {
if ( i<temp.length()/2 )
ans = temp.substr(0,temp.length()-i)+t+temp.substr(temp.length()-i,i);
else ans = temp.substr(0,temp.length()-i-1)+t+temp.substr( temp.length()-i-1,i+1);
flag = true;
}
}
if ( flag ) cout<<ans<<endl;
else cout<<"NA"<<endl;
return 0;
}