Mr. Kitayuta's Gift

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 of s.
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 Input

Input
revive
Output
reviver
Input
ee
Output
eye
Input
kitayuta
Output
NA

Hint

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>
using namespace std;
const int N = 20;
char s[N], p[N];
int l;
bool ispal()
{
for(int i = 0; i < (l + 1) / 2; ++i)
if(p[i] != p[l - i]) return false;
return true;
} int main()
{
int i, j, k;
scanf("%s", s);
l = strlen(s);
for(char c = 'a'; c <= 'z'; ++c)
{
for(k = 0; k <= l; ++k)
{
i = j = -1;
while(i < k - 1) p[++j] = s[++i];
p[++j] = c;
while(i < l - 1) p[++j] = s[++i];
if(ispal())
{
printf("%s\n", p);
return 0;
}
}
}
printf("NA\n");
return 0;
}

code forces 505A的更多相关文章

  1. 思维题--code forces round# 551 div.2

    思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...

  2. Code Forces 796C Bank Hacking(贪心)

    Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...

  3. Code Forces 833 A The Meaningless Game(思维,数学)

    Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...

  4. Code Forces 543A Writing Code

    题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...

  5. code forces 383 Arpa's loud Owf and Mehrdad's evil plan(有向图最小环)

    Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...

  6. code forces 382 D Taxes(数论--哥德巴赫猜想)

    Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

  7. code forces Watermelon

    /* * Watermelon.cpp * * Created on: 2013-10-8 * Author: wangzhu */ /** * 若n是偶数,且大于2,则输出YES, * 否则输出NO ...

  8. code forces Jeff and Periods

    /* * c.cpp * * Created on: 2013-10-7 * Author: wangzhu */ #include<cstdio> #include<iostrea ...

  9. Code Forces Gym 100971D Laying Cables(单调栈)

    D - Laying Cables Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u ...

随机推荐

  1. attachEvent 中this指向

    IE中使用的事件绑定函数与Web标准的不同,而且this指向也不一样,Web标签中的this指向与传统事件绑定中的this一样,是当前目标,但是IE中事件绑定函数中this指向,通过使用call或ap ...

  2. WHY学习python?

    1.python更容易上手 2.功能库很多,不用重复造轮子 3.能干的事情很多(网站开发,爬虫,自动化运维,数据分析,游戏开发,人工智能) 网站开发:豆瓣,知乎 网站框架:django (姜狗) py ...

  3. Spring提供的iBatis的SqlMap配置

    1.    applicationContext.xml <!-- Spring提供的iBatis的SqlMap配置--> <bean id="sqlMapClient&q ...

  4. 使用JSON语法创建JS对象(重要)

    JS对象的键值可以加单引号或者不加或者加双引号 JSON语法提供了一种更简单的方式来创建对象,可以避免书写函数,也可避免用new关键字,可以直接创建一个JS对象,使用一个花括号,然后将每个属性写成&q ...

  5. thinkphp对数据库的增删改查(查询构造器)

  6. python并发编程之gevent协程(四)

    协程的含义就不再提,在py2和py3的早期版本中,python协程的主流实现方法是使用gevent模块.由于协程对于操作系统是无感知的,所以其切换需要程序员自己去完成. 系列文章 python并发编程 ...

  7. android 系统的休眠与唤醒+linux 系统休眠

    Android休眠与唤醒驱动流程分析 标准Linux休眠过程: powermanagement notifiers are executed with PM_SUSPEND_PREPARE tasks ...

  8. netif_start_queue/netif_wake_queue/netif_stop_queue

    在网卡驱动中,内核为发送数据包的流量控制提供了几个主要的函数,用来在驱动程序和内核之间传递流控信息. 主要有4个: 1]netif_start_queue  启动接口传输队列 2]netif_wake ...

  9. Python 生成随机数

    import random x = int(input('Enter a number for x: '))  --随机数最小值y = int(input('Enter a number for y: ...

  10. Docker practice

    Docker 实践 目标 创建一个基于最新版Ubuntu的镜像,在该镜像中更新apt包源并安装NTP package,最后将该新镜像提交到本地私有的registry中. 本地创建私有Registry ...