Codeforces Global Round 4E(字符串,思维)
#include<bits/stdc++.h>
using namespace std;
string s,a,b;
int main(){
cin>>s;
int n=s.size();
int l=0,r=n-1;
while(l<=r-3){//三个字母没有连续相同的,所以四个字符以内必定有相同字母,即回文
if(s[l]==s[r]){
a.push_back(s[l]);
b.push_back(s[r]);
l++,r--;
}
else if(s[l]==s[r-1]){
a.push_back(s[l]);
b.push_back(s[r-1]);
l++,r-=2;
}
else if(s[l+1]==s[r]){
a.push_back(s[l+1]);
b.push_back(s[r]);
l+=2,r--;
}
else if(s[l+1]==s[r-1]){
a.push_back(s[l+1]);
b.push_back(s[r-1]);
l+=2,r-=2;
}
}
if(r>=l)
a.push_back(s[l]);//中间还剩余一个字母,加上它使得串更长,当输入的串很小时,加上中间一个可以使得超过一半
reverse(b.rbegin(),b.rend());//反向迭代器的++是向前的,等同于reverse(b.begin(),b.end());
cout<<a<<b;
return 0;
}
Codeforces Global Round 4E(字符串,思维)的更多相关文章
- Codeforces Global Round 11 个人题解(B题)
Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- Codeforces Global Round 1 - D. Jongmah(动态规划)
Problem Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...
- Codeforces Global Round 2 题解
Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...
- Codeforces Global Round 1 (A-E题解)
Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...
- Codeforces Global Round 3
Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...
- Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)
Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...
- 【手抖康复训练1 】Codeforces Global Round 6
[手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...
- Codeforces Global Round 7 D2. Prefix-Suffix Palindrome (Hard version)(Manacher算法+输出回文字符串)
This is the hard version of the problem. The difference is the constraint on the sum of lengths of s ...
随机推荐
- Windows下配置Erlang环境
1.下载地址 http://www.erlang.org/downloads 2.下载文件 下载 OTP 22.2 Windows 64-bit Binary File 3.配置环境变量 将下载的安装 ...
- Android学习05
AlertDialog(对话框) 它也是其他 Dialog的的父类!比如ProgressDialog,TimePickerDialog等,而AlertDialog的父类是:Dialog! AlertD ...
- C语言:把分数最低的学生数据放入数组b所指的数组中,-从键盘输入若干字符串,写入文件myfile4中,用-1作字符输入结束的标志,
//学生记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组中,fun函数:把分数最低的学生数据放入数组b所指的数组中,分数最低的学生可能不止一个.人数返回. #include <st ...
- Git 安装配置及工作流程
在使用Git前我们需要先安装 Git.Git 目前支持 Linux/Unix.Solaris.Mac和 Windows 平台上运行. Git 各平台安装包下载地址为:http://git-scm.co ...
- Operating systems Chapter 4
There are two processes to switch, when one run:io instruction, switch on other process. After ios, ...
- How2j学习java-2、用命令行中编写第一个 JAVA 程序
真正在工作中开发 java 应用都会使用eclipse,myeclipse, IntelliJ等等 使用最原始的命令行方式来执行Hello World 1.准备项目目录 在e: 创建一个project ...
- Cosmetic Bottles - Cosmetic Packaging: What Are The Characteristics Of Trends?
There are certain differences in products, of which cosmetics are the most obvious. In addition to t ...
- RS232与RS485
1.RS232实物图与引脚图? 2.RS485实物图与引脚图?
- PHP中数字转为百分位,千分位,万分位。。。
今天做项目中,需要将文章点击量显示在页面中,需求中给的是多少多少万,虽然不是什么难事,但做程序员这么久了,需要考虑的不再是简单的实现,而且有效率和快捷, 虽然PHP自带的函数有number_forma ...
- Python:集合类型
概念 无序的,不可随机访问的,不可重复的元素集合 与数学中集合的概念类似,可对其进行相关的运算 集合分为可变集合和非可变集合:set 和 frozenset 定义 可变集合 s = {x1, x2, ...