1354. Palindrome. Again Palindrome

博客围绕1354. Palindrome. Again Palindrome展开,包含输入、输出及示例内容,原文转载自https://www.cnblogs.com/sdau--codeants/p/3275087.html 。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1354. Palindrome. Again Palindrome

Time limit: 1.0 second Memory limit: 64 MB
A word is the nonempty sequence of symbols a1a2an. A palindrome is the word a1a2an that is read from the left to the right and from the right to the left the same way (a1a2an = anan−1a1). If S1 = a1a2an and S2 = b1b2bm, then S1S2 = a1a2anb1b2bm. The input contains some word S1. You are to find a nonempty word S2 of the minimal length that S1S2 is a palindrome.

Input

The first input line contains S1 (it may consist only of the Latin letters). It’s guaranteed that the length of S1 doesn’t exceed 10000 symbols.

Output

S1S2.

Samples

inputoutput
No
NoN
OnLine
OnLineniLnO
AbabaAab
AbabaAababA
Problem Author: Denis Nazarov Problem Source: USU Junior Championship March'2005
***************************************************************************************
kmp没想出来,用简单法做的
***************************************************************************************
 1 #include<iostream>
 2 #include<string>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 #include<cstdio>
 7 #include<queue>
 8 #include<vector>
 9 #include<stack>
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<n;i++)
26       cout<<str[i];
27      for(i=1;i<n;i++)
28       if(judge(i))
29        break;
30     for(j=i-1;j>=0;j--)
31      cout<<str[j];
32     cout<<endl;
33     return 0;
34 
35 
36  }
View Code

 

转载于:https://www.cnblogs.com/sdau--codeants/p/3275087.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值