codeforces Round 286# problem A. Mr. Kitayuta's Gift < 回文串 >
来源:互联网 发布:mac可以玩守望先锋吗 编辑:程序博客网 时间:2024/06/07 02:31
题目:http://codeforces.com/contest/505/problem/A
题意分析:1.字符串全为小写,长度不超过10 2.允许在字符串任意位置插入一个小写字母,判断是否能够变为回文串。 如果能, 输出该串。 不能, 输出 ‘NA’
MA:实在想不出什么好的优化算法, 只好暴力了~~ 思路是遍历每个位置,把字符串数组存到另一数组中,每次并空出一位, 枚举26个字母(其实可以只枚举原串中的就足够)直到变为回文串~~~ 真的是好粗暴。。
#include <cstring>#include <cstdio>const int maxn = 20 + 10;char s[maxn], b[maxn];int is_p(int n){ for(int i = 0, j = n-1; i <= j; i++, j--) if(b[i] != b[j]) return 0; return 1;}int solve(){ int n = strlen(s); memset(b, 0, sizeof(b)); for(int i = 0; i <= n; i++) { for(int j = 0; j < i; j++) b[j] = s[j]; for(int j = i; j < n; j++) b[j+1] = s[j]; for(char k = 'a'; k <= 'z'; k++) { b[i] = k; if(is_p(n+1)) { printf("%s\n", b); return 1; } } } return 0;}int main(){ while(~scanf("%s", s)) { if(!solve()) printf("NA\n"); memset(s, 0, sizeof(s)); } return 0;}
0 0
- codeforces Round 286# problem A. Mr. Kitayuta's Gift < 回文串 >
- Codeforces Round #286 (Div. 2)-A. Mr. Kitayuta's Gift
- Codeforces Round #286 (Div. 2) A. Mr. Kitayuta's Gift
- CF 505A(Mr. Kitayuta's Gift-回文串)
- [Codeforces Round #286 DIV1E (CF506E)] Mr. Kitayuta's Gift
- Codeforces 505A Mr. Kitayuta's Gift
- Codeforces Round #286 (Div. 2) A - Mr. Kitayuta's Gift ( 暴力枚举)std:string::insert
- A. Mr. Kitayuta's Gift
- A. Mr. Kitayuta's Gift
- A. Mr. Kitayuta's Gift
- Codeforces 505A. Mr. Kitayuta's Gift 水
- 暴力字符串 Codeforces Div. 2 A Mr. Kitayuta's Gift
- Codeforces 505A Mr. Kitayuta's Gift 题解
- Mr. Kitayuta's Gift
- Mr. Kitayuta's Gift
- A. Mr. Kitayuta's Gift(暴力求加一个字符是否构成回文字符)
- Codeforces Round #286 (Div. 2) D.Mr. Kitayuta's Technology
- [Codeforces Round #286 DIV1B (CF506B)] Mr. Kitayuta's Technology
- 杭电oj 1096 A+B for Input-Output Practice (VIII)
- Imgproc_4_图像轮廓
- 基本数据类型与引用数据类型参数传递
- iOS编程(双语版)-视图-Frame/Bounds/Center
- Centos7 下mysql安装配置
- codeforces Round 286# problem A. Mr. Kitayuta's Gift < 回文串 >
- 二叉树的一些笔试面试常见题目
- 17缓冲流原理
- PendingIntent和Intent
- codeforces 671B
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations(线段树)
- Ajax跨域请求——jsonp技术
- 96.苹果企业证书过期与Appstore证书与描述文件过期解决方案-描述文件过期的方案
- iOS开发小点之启动广告界面