水题 Codeforces Round #286 (Div. 2) A Mr. Kitayuta's Gift
/*
水题:vector容器实现插入操作,暴力进行判断是否为回文串
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
vector<char> s;
char ss[]; bool check(void)
{
for (int i=, j=s.size ()-; i<j; ++i, --j)
if (s[i] != s[j]) return false;
return true;
} int main(void) //Codeforces Round #286 (Div. 2) A Mr. Kitayuta's Gift
{
//freopen ("A.in", "r", stdin); while (cin >> ss)
{
s.clear (); bool flag = false;
for (int i=; ss[i]; ++i) s.push_back (ss[i]);
for (int i=; i<=s.size (); ++i)
{
for (int j=; j<=; ++j)
{
char ch = 'a' + j;
s.insert (s.begin () + i, ch);
if (check ())
{
flag = true;
for (int i=; i<s.size (); ++i)
cout << s[i];
cout << endl; break;
}
else s.erase (s.begin () + i);
}
if (flag) break;
} if (!flag) cout << "NA" << endl;
} return ;
}
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f; bool ok(string x)
{
string ss = x;
reverse (ss.begin (), ss.end ());
return (ss == x);
} int main(void) //Codeforces Round #286 (Div. 2) A Mr. Kitayuta's Gift
{
//freopen ("A.in", "r", stdin); string s;
cin >> s; int len = s.size ();
for (int i=; i<=len; ++i)
{
for (char c='a'; c<='z'; ++c)
{
string x;
for (int j=; j<i; ++j) x += s[j];
x += c;
for (int j=i; j<len; ++j) x += s[j];
if (ok (x)) {cout << x << endl; return ;}
}
}
cout << "NA" << endl; return ;
}
string 实现
水题 Codeforces Round #286 (Div. 2) A Mr. Kitayuta's Gift的更多相关文章
- Codeforces Round #286 (Div. 2)A. Mr. Kitayuta's Gift(暴力,string的应用)
由于字符串的长度很短,所以就暴力枚举每一个空每一个字母,出现行的就输出.这么简单的思路我居然没想到,临场想了很多,以为有什么技巧,越想越迷...是思维方式有问题,遇到问题先分析最简单粗暴的办法,然后一 ...
- DFS/并查集 Codeforces Round #286 (Div. 2) B - Mr. Kitayuta's Colorful Graph
题目传送门 /* 题意:两点之间有不同颜色的线连通,问两点间单一颜色连通的路径有几条 DFS:暴力每个颜色,以u走到v为结束标志,累加条数 注意:无向图 */ #include <cstdio& ...
- Codeforces Round #286 (Div. 1) D. Mr. Kitayuta's Colorful Graph 并查集
D. Mr. Kitayuta's Colorful Graph Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/ ...
- Codeforces Round #286 (Div. 1) B. Mr. Kitayuta's Technology (强连通分量)
题目地址:http://codeforces.com/contest/506/problem/B 先用强连通判环.然后转化成无向图,找无向图连通块.若一个有n个点的块内有强连通环,那么须要n条边.即正 ...
- Codeforces Round #286 Div.1 A Mr. Kitayuta, the Treasure Hunter --DP
题意:0~30000有30001个地方,每个地方有一个或多个金币,第一步走到了d,步长为d,以后走的步长可以是上次步长+1,-1或不变,走到某个地方可以收集那个地方的财富,现在问走出去(>300 ...
- Codeforces Round #286 (Div. 2) B. Mr. Kitayuta's Colorful Graph dfs
B. Mr. Kitayuta's Colorful Graph time limit per test 1 second memory limit per test 256 megabytes in ...
- Codeforces Round #286 (Div. 1) D. Mr. Kitayuta's Colorful Graph
D - Mr. Kitayuta's Colorful Graph 思路:我是暴力搞过去没有将答案离线,感觉将答案的离线的方法很巧妙.. 对于一个不大于sqrt(n) 的块,我们n^2暴力枚举, 对于 ...
- Codeforces Round #286 (Div. 2)B. Mr. Kitayuta's Colorful Graph(dfs,暴力)
数据规模小,所以就暴力枚举每一种颜色的边就行了. #include<iostream> #include<cstdio> #include<cstdlib> #in ...
- 水题 Codeforces Round #302 (Div. 2) A Set of Strings
题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...
随机推荐
- android keyEvent
http://developer.android.com/reference/android/view/KeyEvent.html
- Mac OS用docker Desktop安装单节点kubernetes
方案: 安装方式:阿里云minikube,k8s官方minikube,kubeadm, docker Desktop中自带第k8s 安装环境:在linux虚拟机中安装k8s,在macos中安装k8s, ...
- JavaScript 实现块级作用域
(function(){ 块级作用域: })();
- 如何设计一个优秀的API
如何设计一个优秀的API - 文章 - 伯乐在线 http://blog.jobbole.com/42317/ 如何设计一个优秀的API - 标点符 https://www.biaodianfu.co ...
- 如何去除Office Excel的密码保护?
企图更改Excel文件内容,然而却弹出如下提示: 根据提示,我尝试解除保护表,却要求输入密码: 这就尴尬了=_=密码不是我设定的 问了度娘,找到了解决方案 将Excel文件扩展名更改为rar, 使用压 ...
- HTML——使用表格进行页面布局
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Echarts饼状图
<head> <meta charset="utf-8"> <title>ECharts</title> <script sr ...
- 「ZJOI2008」「LuoguP2590」树的统计(树链剖分
题目描述 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w. 我们将以下面的形式来要求你对这棵树完成一些操作: I. CHANGE u t : 把结点u的权值改为t II. QMAX u ...
- 微信小程序开发之https从无到有
本篇不讲什么是https,什么是SSL,什么是nginx 想了解这些的请绕道,相信有很多优秀的文章会告诉你. 本篇要讲的在最短的时间内,让你的网站从http升级到https. 开始教程前再说一句:ht ...
- 孙鑫C++教学视频
视频百度云:https://pan.baidu.com/s/1jKf6GoY 在线观看:http://list.youku.com/albumlist/show?id=3567028&asce ...