1297. Palindrome

Time limit: 1.0 second
Memory limit: 64 MB
The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlimited» has infiltrated into “U.S. Robotics”. «U.S. Robots» security service would have already started an undercover operation to establish the agent’s identity, but, fortunately, the letter describes communication channel the agent uses. He will publish articles containing stolen data to the “Solaris” almanac. Obviously, he will obfuscate the data, so “Robots Unlimited” will have to use a special descrambler (“Robots Unlimited” part number NPRx8086, specifications are kept secret).
Having read the letter, the “U.S. Robots” president recalled having hired the “Robots Unlimited” ex-employee John Pupkin. President knows he can trust John, because John is still angry at being mistreated by “Robots Unlimited”. Unfortunately, he was fired just before his team has finished work on the NPRx8086 design.
So, the president has assigned the task of agent’s message interception to John. At first, John felt rather embarrassed, because revealing the hidden message isn’t any easier than finding a needle in a haystack. However, after he struggled the problem for a while, he remembered that the design of NPRx8086 was still incomplete. “Robots Unlimited” fired John when he was working on a specific module, the text direction detector. Nobody else could finish that module, so the descrambler will choose the text scanning direction at random. To ensure the correct descrambling of the message by NPRx8086, agent must encode the information in such a way that the resulting secret message reads the same both forwards and backwards.
In addition, it is reasonable to assume that the agent will be sending a very long message, so John has simply to find the longest message satisfying the mentioned property.
Your task is to help John Pupkin by writing a program to find the secret message in the text of a given article. As NPRx8086 ignores white spaces and punctuation marks, John will remove them from the text before feeding it into the program.

Input

The input consists of a single line, which contains a string of Latin alphabet letters (no other characters will appear in the string). String length will not exceed 1000 characters.

Output

The longest substring with mentioned property. If there are several such strings you should output the first of them.

Sample

input output
ThesampletextthatcouldbereadedthesameinbothordersArozaupalanalapuazorA
ArozaupalanalapuazorA
Problem Author: Eugene Krokhalev
Problem Source: IX Open Collegiate Programming Contest of the High School Pupils (13.03.2004)
Difficulty: 93    Printable version    Submit solution    Discussion (71)
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int N=1e6+;
char s[N],S[N<<];
int l,p[N];
void manacher(){
int mx=-,id=,ans=,pos=;
for(int i=;i<l;i++){
if(id+mx>i) p[i]=min(p[id*-i],id+mx-i);
while(i-p[i]->=&&i+p[i]+<=l&&S[i-p[i]-]==S[i+p[i]+]) p[i]++;
if(id+mx<i+p[i]) id=i,mx=p[i];
if(ans<p[i]) ans=p[i],pos=i;
}
bool f=;
if(S[pos]!='#') pos++;else f=;
pos/=;ans/=;
s[pos+ans+]=;pos-=ans;
if(f) pos++;
puts(s+pos); }
int main(){
while(scanf("%s",s+)==){
int len=strlen(s+);
l=-;
for(int i=;i<=len;i++) S[++l]='#',S[++l]=s[i];
S[++l]='#';
manacher();
}
return ;
}
/*
in:
oUtkzqGlUgWNznyqfXYTPFLgaQrHORMTuKJZtFsmAcWGgMJvtSrRIjElhsCiSGKCFFrHpxdcmQnEZpYsujebwDWhwMbyuDWWHWBJJQlxeCVgokrOuTGbRfVmlionoQiQPGkvMmfNfhohxQvseSoUZOKkXTVxiElofJtujfZPVBWfKBrCrmEyznOUorfwpsYirVQdKwKKWOHoYLDuqqczmqPHBBVpaqldmhmiEdgeqaspGyFbYqdsARnqzcjmjgtndaTpfeFfvVVvooCyOdnelFzDqjzcqRKckRXTnQCWvPRmpnnrRfveyGpWqxcLqEOmotDisqghJtwcouyanxyRAdUvqdLlIvElpleVqEcxBvuYnhTGsoZIfdTdnuCVWOjbfUFtZbaXCIvNaJMsVfhAZfwbHQnmXosLByYxgpCPisNtEuEQsZRZpCTRobllnIYFUKpovYAxhnAUlAamcdkOvZdAHWrGksuYkoOvebZEPGnHZfbvKVgFyrxCtcNzBYpOFgKhSvGPQkEtiRbsQaxAJqlPgnVmTdJXHpmQgVHOCeoSmamjQduUAiRYanAOYgVRmCigUMvFkQSSbNvwTEfozQaucpVIqJHYgtIuxPZZwSySCSkEBnZupGjObKQGQkVCwmtovnjjomQfdieqAxbwpVcEVChnhwuyAagRoqVtDXsThdcWKAFZNAlKkrDwHQFuQwBssJzhKSrotpApDGtUFBngTIZDKMsVVKxTtkKKpdaxfWQrvJelGANVdBnkjATsMMyaLnrOxZnPXGEgBxtr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lEdVfbyfGgbtDVezgjSMLjJmJRFRWYKcBHQpPNihWhBLZurbxhXdNmVwzqyGsoTbucCVxkTkBBviDRJlZVfUnygxmHWbMdDOFHlNZbWfGDJItLDDOCZGkoTprZkAtJgikTHWgEziBNxdspLYliEsOdINixFXBgyNZuSlfwfnIvtFBvYDrRRojBwOiYhjIvHhBquUWSsaScmikxKMsAZsweijSQivoJlUMzyOlwQQIELhdvERYwxxKPoTayBfDxxsCPmWrYXgcfuUNeZvFJoKSlEDQidZdBKZnOGAJaFQwbgKPfCEVBcfSmTgucgKJnkYbbFoXDojHSiUHdkzinrygmyWxtKhlxKvCSwkVApomeausoMTbdmioiFbEgAEYimAzLVLWhITtKEuiIcZEOfGvjOYhjBXlzuKixHyULLkEiWrZuPAjnnmgTwynuFtuydaYhmtBtXuebpBeCKPNibWzycLFiEdZdQkApqFNHlXUkSWkxdLxRBnzTcxXYZzmjjRA out:
vVVv
*/

最新文章

  1. [No0000AD]7z源码完全移植至Visual Studio 2015
  2. 【从html到算法框架】科技白学习计划书
  3. sql 2012中获取表的信息,包含字段的描述
  4. 【转】java NIO 相关知识
  5. android模拟器没法通过localhost访问本地服务器的解决
  6. 15个来自 CodePen 的酷炫 CSS 动画效果【下篇】
  7. json数组的序列化和反序列化json数组的序列化和反序列化
  8. [转]va_start和va_end使用详解
  9. Silverlight弹出层(转载)
  10. NFA与DFA
  11. 处理器在 protected mode 下的 protection
  12. thinkphp I方法取传参
  13. HDU Today(dijskra)
  14. [刷题]Google Code Jam 2017 - Round1 C Problem A. Ample Syrup
  15. 【Socket编程】通过Socket实现TCP编程
  16. Java求循环节长度
  17. Ceilometer + Aodh + Gnocchi 介绍
  18. springboo+nginx测试反向代理01
  19. 动态规划 hdu 1024
  20. bzoj4361 isn(树状数组优化dp+容斥)

热门文章

  1. XMind--用他来理清自己的思路
  2. 机器学习实战笔记7(Adaboost)
  3. 在Windows8系统下exe格式会计课件下载播放帮助图解
  4. Java并发编程(六):Java里实现对象安全发布的四种方式
  5. Sublime Text 2 入门与总结
  6. [转]Ubuntu 12.04.3 LTS 安装 Qt5.1.1
  7. 小马哥课堂-统计学-t分布(2)
  8. 5.3日,7:20开始 阮一峰js的早课学习
  9. 完工尚需绩效指数 TCPI
  10. Struts1小案例问题教训总结(含中文乱码问题及解决)