#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(字符串,思维)的更多相关文章

  1. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

  2. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  3. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  4. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  5. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  6. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  7. Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

  8. 【手抖康复训练1 】Codeforces Global Round 6

    [手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...

  9. 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 ...

随机推荐

  1. 计算机二级-C语言-程序填空题-190109记录-对二维字符串数组的处理

    //给定程序,函数fun的功能是:求出形参ss所指字符串数组中最长字符串的长度,将其余字符串右边用字符*补齐,使其与最长的字符串等长.ss所指字符串数组中共有M个字符串,且串长<N. //重难点 ...

  2. Hadoop3.1.1源码Client详解 : 写入准备-RPC调用与流的建立

    该系列总览: Hadoop3.1.1架构体系——设计原理阐述与Client源码图文详解 : 总览 关于RPC(Remote Procedure Call),如果没有概念,可以参考一下RMI(Remot ...

  3. android开发基础(ViewModel)

    今天学习了ViewModel,其是Jetpack的一个类,它可以将界面中的数据独立出来,这样不会造成页面上信息的丢失. 我跟着视频做了一个简单的实例: 首先创建项目的时候它和以往的项目会有些不一样,因 ...

  4. static静态变量使用@Value注入方式

    @Componentpublic class MyConfig { private static String env; public static String getEnv() { return ...

  5. SDNU_ACM_ICPC_2020_Winter_Practice_1st

    A Petya is a big fan of mathematics, esecially its part related to fractions. Recently he learned th ...

  6. js下false情况

    //为false的情况 false null NaN undefined "" 0

  7. 计算机二级-C语言-程序填空题-190115记录-fprintf()函数和fscanf()函数的使用。

    //给定程序,函数fun的功能是:将自然数1~10以及它们的平方根写到名为myflie3.txt的文本文件中,然后再顺序读出显示在屏幕上. //重难点:fprintf()函数和fscanf()函数的使 ...

  8. No space left on device(转载)

    本文转自 http://blog.163.com/ly_89/blog/static/186902299201191233058625/ =====================概述======== ...

  9. 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(4)

    # -*- coding: utf-8 -*- import glob import os.path import numpy as np import tensorflow as tf from t ...

  10. UCS内存问题排查

    UCS使用双列直插式内存模块(Dual In-line Memory Module (DIMM) )作为RAM模块. 根据文档介绍,主要有如下部分:1.Memory placement <内存放 ...