A. Mr. Kitayuta's Gift

来源:互联网 发布:淘宝客服是几点上班 编辑:程序博客网 时间:2024/05/17 07:53

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.

You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end ofs. You have to insert a letter even if the given string is already a palindrome.

If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that 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 English letter.

Output

If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will 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 is more than one solution. For example, "eve" will also be accepted.

For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.



解题说明:此题是一道回文判断题,先按逆序保存字符串,然后再判断添加什么字母构成回文。


#include<cstdio>#include <cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>using namespace std;int main(){    char s[11],r[12];int l,i,j;    scanf("%s",s);    l=strlen(s);    for(i=0;i<=l;i++)    {        if(i<(l/2+1))        {r[i]=s[l-1-i];}else {r[i]=s[l-i];}        for(j=0;j<i;j++)        {r[j]=s[j];}for(j=i+1;j<=l;j++)        {r[j]=s[j-1];}   r[l+1]='\0';        for(j=0;j<(l/2+1);j++)        {            if(r[j]!=r[l-j]){break;}        }        if(j==(l/2+1)){break;}    }    if(i==l+1){printf("NA\n");}else {printf("%s\n",r);}return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 数字油画的颜料干了怎么办 丙烯颜料画错了怎么办 油画的油干了怎么办 数字油画没画完颜料干了怎么办? 涂完口红很干怎么办 吃鸡匹配不到人怎么办 电脑吃鸡更新慢怎么办 苹果手机吃鸡更新不了怎么办 吃鸡更新硬盘不够怎么办 吃鸡链接不到更新服务器怎么办 6s吃鸡更新不了怎么办 凌美钢笔刮纸怎么办 毕加索钢笔不出水怎么办妙招 打印机总显示墨水已用完怎么办 樱花勾线笔干了怎么办 枣核卡在喉咙里怎么办 马桶被玉米棒堵了怎么办 雪糕棒掉马桶里了怎么办 食用色素吃多了怎么办 蜡笔弄到指甲里怎么办 小孩把彩笔吃了怎么办 宝宝吃了水彩笔怎么办 宝宝不小心吃了蜡笔怎么办 小孩把蜡笔吃了怎么办 宝宝吃了记号笔怎么办 二年级的孩子不太爱看书怎么办 数字油画涂错了怎么办 白墙上被蜡笔画起来怎么办 衣服上的油画棒怎么办 蜡笔要是涂错了怎么办 蜡笔颜色涂错了怎么办 书被蜡笔涂了怎么办 白灰墙上被蜡笔涂了怎么办 电器上涂了彩色蜡笔怎么办 3d渲大图慢怎么办 23岁就眼皮下垂怎么办 手被猫咪抓破了怎么办 有幻想症的人怎么办 做事不专心老走神怎么办 小朋友做作业老发呆走神怎么办? 小朋友总是上课走神发呆怎么办