题目链接:http://codeforces.com/contest/505/problem/A
解题思路:
暴力求解,对于每一个位置,都用a到z进行插入,如果有符合条件的,直接输出。否则输出NA
完整代码:
//#include <bits/stdc++.h>
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long LL;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;
/*
__gcd(a, b) // My gcd
__builtin_ffs(x) //My lowbit
__builtin_popcount(x) //The number of 1-bits
*/
/** Constant List .. **/ //{
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;
string s;
bool check(string t)
{
int len = t.length();
for(int i = 0 , j = len - 1 ; i < j ; i ++ , j --)
{
if(t[i] != t[j])
return false;
}
return true;
}
int main()
{
#ifdef DoubleQ
freopen("in.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
std::cin.tie(0);
while(cin >> s)
{
int n = s.length();
int flag = 0;
for(int i = 0 ; i <= n ; i ++)
{
for(int j = 0 ; j < 26 ; j ++)
{
string t = "";
for(int k = 0 ; k < i ; k ++)
t += s[k];
t += (char)(j + 'a');
for(int k = i ; k < n ; k ++)
t += s[k];
if(check(t))
{
cout << t << endl;
flag = 1;
break;
}
}
if(flag)
break;
}
if(flag == 0)
cout << "NA" << endl;
}
}