Mr Kitayuta have kindly given you a string s consisting of lowercase 中文版 letters. You is asked to insert exactly one lowercase 中文版 letter into s -make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" is all palindromes, while "test" and "Kitayuta" is not.
can choose any lowercase 中文版, and insert it to any position of s, possibly to the beginning or The end of s. You had to insert a letter even if the given string is already a palindrome.
If It is possible to insert one lowercase 中文版 into s so, the resulting string would be a palind Rome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there was more than one palindrome so can be obtained, you are allowed to print any of them.
Input
The only line of the input contains a string s (1≤| S| ≤10). Each character in s is a lowercase 中文版.
Output
If It is possible to turn s into a palindrome by inserting one lowercase 中文版 letter, print the resulting String in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there are more than one solution, and any of the them would be accepted.
Sample Test (s) input
Revive
Output
Reviver
Input
Ee
Output
Eye
Input
Kitayuta
Output
NA
Note
For the first sample, insert 'R ' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there are more than one solution. For example, "Eve" would also be accepted.
For the third sample, it isn't possible to turn 'Kitayuta ' into a palindrome by just inserting one letter.
Portal: Http://codeforces.com/contest/505/problem/A
Test instructions Analysis: 1. The string is all lowercase, and the length does not exceed 10 2. Allows you to insert a lowercase letter anywhere in the string to determine if it can become a palindrome. If it can, output the string. No, output ' NA '
MA: I can not think of any good optimization algorithm, had to violence ~ ~ The idea is to traverse each position, the string array into another array, each time and empty a bit, enumerate 26 letters (in fact, it is enough to enumerate the original string) until it becomes a palindrome string ~ ~ really is good rough.
Code:
#include <cstring>#include<cstdio>Const intMAXN = -+Ten;CharS[MAXN], B[MAXN];intIs_p (intN) { for(inti =0, j = N1; I <= J; i++, j--)if(B[i]! = B[j])return 0; return 1;}intsolve () {intn =strlen (s); memset (b,0,sizeof(b)); for(inti =0; I <= N; i++){ for(intj =0; J < I; J + +) B[j] =S[j]; for(intj = i; J < N; J + +) b[j+1] =S[j]; for(CharK ='a'; K <='Z'; k++) {//Here you can optimizeB[i] =K; if(Is_p (n+1) {printf ("%s\n", B); return 1; } } } return 0;}intMain () { while(~SCANF ("%s", s)) { if(!solve ()) printf ("na\n"); memset (s),0,sizeof(s)); } return 0;}
View Code
Codeforces Round 286# problem A. Mr Kitayuta ' s Gift