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 ...
随机推荐
- 三大查找算法(Java实现)
三大查找算法 1.二分查找(Binary Search) public class BinarySearch { public static void main(String[] args) { in ...
- Django objects.all()、objects.get()与objects.filter()之间的区别介绍
前言 本文主要介绍的是关于Django objects.all().objects.get()与objects.filter()直接区别的相关内容,文中介绍的非常详细,需要的朋友们下面来一起看看详细的 ...
- uniGUI之文件下载(29)
1]SendFile 2]SendStream 3]自定义类型文件下载 1]SendFile UniSession.SendFile('新建文本文档.txt' //服务器端 文件名 ,'anew.tx ...
- css3的一些特效
前段时间有位同事分享了一个网站,里边是一些css3特效,看着挺好,分享一下: [http://daneden.github.io/animate.css/ ] 所有的特效都集中在一个css层叠样式表中 ...
- java 面试题 高阶版
1.hash 算法问题 hash(n) /服务器个数 hash 算法在服务器增加或者减少的时候,数据存取位置为发生变化: 什么是一致性hash算法? 一致性hash算法对2^32 取模,整个Hash空 ...
- 安装go1.11.2
1. 设置go环境变量 vim $HOME/.bashrc export GOROOT=$HOME/go export PATH=$PATH:$GOROOT/bin export GOPATH=$HO ...
- 我的 Python 编码规范
python 文件的组成 为了便于描述,先上一个 demo #!/usr/bin/env python # -*- coding: utf-8 -*- """通常这里是关 ...
- 吴裕雄 python 神经网络——TensorFlow训练神经网络:不使用正则化
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_NODE = 784 ...
- HDU1024 Max Sum Plus Plus (优化线性dp)
Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we ...
- Promise解决回调地狱(多层调用问题)
Promise # Promise 是异步编程的一种解决方案:从语法上讲,promise是一个对象,从它可以获取异步操作的消息:从本意上讲,它是承诺,承诺它过一段时间会给你一个结果.promise有三 ...