CF 505A Mr. Kitayuta's Gift

题意 在一个字符串中插入一个字母使其变成一个回文串 可以的话输出这个回文串 否则NA

大水题 插入情况最多就26*11种 可以直接暴力

#include

#include

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;

}

复制代码

A. Mr. Kitayuta‘s Gift 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 test(s) input

revive

[/code]

output

reviver

[/code]

input

ee

[/code]

output

eye[/code]

input

kitayuta

[/code]

output

NA[/code]

文章由http://yy.china.com.cn/shnk/xb/整篇转载

CF 505A Mr. Kitayuta's Gift

时间: 2024-10-24 12:23:22

CF 505A Mr. Kitayuta's Gift的相关文章

CF 505A Mr. Kitayuta&#39;s Gift(暴力)

题意  在一个字符串中插入一个字母使其变成一个回文串  可以的话输出这个回文串  否则NA 大水题  插入情况最多就26*11种  可以直接暴力 #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 -

codeforces 505A. Mr. Kitayuta&#39;s Gift 解题报告

题目链接:http://codeforces.com/problemset/problem/505/A 题目意思:给出一个长度不大于10的小写英文字符串 s,问是否能通过在字符串的某个位置插入一个字母,使得新得到的字符串成为回文串. /**************************************(又到自我反省时刻) 做的时候,通过添加一个单位使得长度增加1,找出中点,检验前一半的位置,找出对称位置替换成对应的前一半位置的字符,然后原字符串剩下的部分追加到后面,再判断回文.但是由于

codeforces Round 286# problem A. Mr. Kitayuta&#39;s Gift

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

286DIV1E. Mr. Kitayuta&#39;s Gift

题目大意 给定一个由小写字母构成的字符串$s$,要求添加$n(n\le 10^9)$个小写字母,求构成回文串的数目. 简要题解 $n$辣么大,显然要矩阵快速幂嘛. 考虑从两端开始构造以s ss为子串的回文串,该回文串长度为$N=n+s$,每次添加相同的字符,则需要$(N+1)/2$次,则用dp来计算并使用矩阵乘法来优化转移会得到一个$O(|s|^6\log N)$的算法,显然是不可接受的. 考虑这个dp做法,设$f[i][j][k]$表示从两端添加了$k$次字符,原来的$s$的子串$s_{ij}

Codeforces 505 A Mr. Kitayuta&#39;s Gift【暴力】

题意:给出一个字符串,可以向该字符串的任意位置插入一个字母使其变成回文串 因为字符串的长度小于10,枚举插入的字母,和要插入的位置,再判断是否已经满足回文串 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<vector> 7 #include<map> 8

CF 505B Mr. Kitayuta&#39;s Colorful Graph(最短路)

题意  求两点之间有多少不同颜色的路径 范围比较小  可以直接floyd #include<cstdio> #include<cstring> using namespace std; const int N = 105; int d[N][N][N], ans; int main() { int a, b, c, n, m, q; while(~scanf("%d%d", &n, &m)) { memset(d, 0, sizeof(d));

Codeforces Round #286 (Div. 2)A. Mr. Kitayuta&#39;s Gift(暴力,string的应用)

由于字符串的长度很短,所以就暴力枚举每一个空每一个字母,出现行的就输出.这么简单的思路我居然没想到,临场想了很多,以为有什么技巧,越想越迷...是思维方式有问题,遇到问题先分析最简单粗暴的办法,然后一步一步的优化,不能盲目的想. 这道题要AC的快需要熟悉string的各种用法.这里做个简单总结:C++中string的常见用法. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstrin

Mr. Kitayuta&#39;s Gift

1 //回文判断 Codeforces Round #286 (Div. 2) 2 #include<iostream> 3 #include<cstdio> 4 int main() 5 { 6 string f,temp; cin>>f; 7 int len(f.size()); 8 for(char c ='a';c<='z';c++) 9 { 10 temp.clear(); 11 temp.push_back(c); 12 for(int i=0;i&l

水题 Codeforces Round #286 (Div. 2) A Mr. Kitayuta&#39;s Gift

题目传送门 1 /* 2 水题:vector容器实现插入操作,暴力进行判断是否为回文串 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <string> 9 #include <vector> 10 using namespace std; 11 12 const int MAXN