Codeforces Round #286 (Div. 2) A.(回文串暴力)
来源:互联网 发布:博彦科技面试题php 编辑:程序博客网 时间:2024/05/22 00:14
题目链接:http://codeforces.com/contest/505/problem/A
解题思路:
暴力求解,对于每一个位置,都用a到z进行插入,如果有符合条件的,直接输出。否则输出NA
完整代码:
//#include <bits/stdc++.h>#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/*__gcd(a, b) // My gcd__builtin_ffs(x) //My lowbit__builtin_popcount(x) //The number of 1-bits*//** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;string s;bool check(string t){ int len = t.length(); for(int i = 0 , j = len - 1 ; i < j ; i ++ , j --) { if(t[i] != t[j]) return false; } return true;}int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif std::ios::sync_with_stdio(false); std::cin.tie(0); while(cin >> s) { int n = s.length(); int flag = 0; for(int i = 0 ; i <= n ; i ++) { for(int j = 0 ; j < 26 ; j ++) { string t = ""; for(int k = 0 ; k < i ; k ++) t += s[k]; t += (char)(j + 'a'); for(int k = i ; k < n ; k ++) t += s[k]; if(check(t)) { cout << t << endl; flag = 1; break; } } if(flag) break; } if(flag == 0) cout << "NA" << endl; }}
0 0
- Codeforces Round #286 (Div. 2) A.(回文串暴力)
- Codeforces Round #427 (Div. 2) D-Palindromic characteristics (回文串,暴力)
- Codeforces Round #329 (Div. 2) A. 2Char 字符串+暴力
- Codeforces Round #243 (Div. 2) A,B,C(暴力枚举)
- Codeforces Round #271 (Div. 2) --A Keyboard (暴力)
- Codeforces Round #283 (Div. 2)---A. Minimum Difficulty (暴力)
- Codeforces Round #281 (Div. 2)A(构造+暴力模拟)
- Codeforces Round #344 (Div. 2) A 题题解 (暴力)
- Codeforces Round #354 (Div. 2)(A)暴力,模拟
- Codeforces Round #387(Div. 2)A. Display Size【暴力】
- Codeforces Round #396 (Div. 2) A---C 暴力+dp
- Codeforces Round #433 (Div. 2) A.Fraction(暴力)
- Codeforces Round #447 (Div. 2) A. QAQ 暴力
- Codeforces Round #286 (Div. 2) A - Mr. Kitayuta's Gift ( 暴力枚举)std:string::insert
- Codeforces Round #389 (Div. 2) D. Santa Claus and a Palindrome 回文串+贪心+数据结构、字符串
- Codeforces Round #336 (Div. 2) B 暴力
- Codeforces Round #309 (Div. 2) B 暴力
- Codeforces Round #363 (Div. 2) B 暴力
- 对跨域SSO(单点登录)思路的补充(UML 顺序图)
- js 字符串转换成数字的三种方法
- Android应用启动画面实现
- 关于Eclipse安装Scala插件不显示
- 当传统企业遇上大数据
- Codeforces Round #286 (Div. 2) A.(回文串暴力)
- 如何个性化的设置自己的博客
- Groovy中closure的delegate
- 通过filezilla向raspberry pi传送文件
- android游戏开发(1)
- VMware GSX Server 3.2.1官方下载地址
- 第18、19讲 项目1体会函数参数传递
- Morphia一个nosql的ORM框架
- [安卓破解]Awind Mirrop Sender 1.1.6.5破解版