1354. Palindrome. Again Palindrome
Time limit: 1.0 second Memory limit: 64 MB
A word is the nonempty sequence of symbols a 1 a 2… an. A palindrome is the word a 1 a 2… an that is read from the left to the right and from the right to the left the same way ( a 1 a 2… an = ana n−1… a 1). If S 1 = a 1 a 2… an and S 2 = b 1 b 2… bm, then S 1 S 2 = a 1 a 2… an b 1 b 2… bm. The input contains some word S 1. You are to find a nonempty word S 2 of the minimal length that S 1 S 2 is a palindrome.
Input
The first input line contains S 1 (it may consist only of the Latin letters). It’s guaranteed that the length of S 1 doesn’t exceed 10000 symbols.
Output
S 1 S 2.
Samples
input | output |
---|---|
No | NoN |
OnLine | OnLineniLnO |
AbabaAab | AbabaAababA |
Problem Author: Denis Nazarov Problem Source: USU Junior Championship March'2005
***************************************************************************************
kmp没想出来,用简单法做的
***************************************************************************************
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 using namespace std;11 char str[10011];12 int n,i,j,k;13 bool judge(int x)//检查后缀的最大回文14 {15 int h,g;16 for(h=x,g=n-1;g>h;h++,g--)17 if(str[h]!=str[g])18 return false;19 return true;20 }21 int main()22 {23 scanf("%s",str);24 n=strlen(str);25 for(i=0;i =0;j--)31 cout<