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. DLL初试

    环境: VC++6.0 步骤: 1.建立一个WIN32 DYNAMIC-LINK LIBRARY工程,编写CPP文件,文件内容例如: #include "stdafx.h" #in ...

  2. python匹配某个中文字符

    python2.7对中文的支持不好是众所周知的,现在遇到这样一个需求,要匹配某个中文字符.查了一个资料,思路就是转化为unicode进行比较,记录如下: line = '参考答案: A' # gbk ...

  3. javascript 获取函数形参

    /** * 获取函数的形参个数 * @param {Function} func [要获取的函数] * @return {*} [形参的数组或undefind] */ function getFunc ...

  4. c语言中使用自带的qsort(结构体排序)+ 快排

    c中没有自带的sort函数emm 不过有自带的qsort函数 (其实用法都差不多(只是我经常以为c中有sort 头文件要用 #include <stdlib.h> 一定要重新把指针指向的值 ...

  5. 【BZOJ】4316: 小C的独立集 静态仙人掌

    [题意]给定仙人掌图,求最大独立集(选择最大的点集使得点间无连边).n<=50000,m<=60000. [算法]DFS处理仙人掌图 [题解]参考:[BZOJ]1023: [SHOI200 ...

  6. amcharts的一些用法

    function chartdiv2() { var chart; var chartData = [ { "month" : "2015-08", " ...

  7. from 表单多文本提交不为空

    假设需要提交4个文本,均不为空: <form id="form" onsubmit="return check()"> </form> ...

  8. JS设计模式——5.单体模式(用了这么久,竟全然不知!)

    单体模式的优势 用了这么久的单体模式,竟全然不知!用它具体有哪些好处呢? 1.可以用它来划分命名空间(这个就是就是经常用的了) 2.利用分支技术来封装浏览器之间的差异(这个还真没用过,挺新鲜) 3.借 ...

  9. CTF AWD模式攻防Note

    ###0x01 AWD模式 Attack With Defence,简而言之就是你既是一个hacker,又是一个manager.比赛形式:一般就是一个ssh对应一个web服务,然后flag五分钟一轮, ...

  10. JS时间转换的一个坑位

    在做项目的时候,无意发现了一个小东西. new Date('2018-05-15') new Date('2018-5-15') 输出的结果是不同的,相差了8小时.然后让我回忆到之前看的一个时间转换函 ...