基准时间限制:1 秒 空间限制:131072 KB 分值: 0
难度:基础题
回文串是指aba、abba、cccbccc、aaaa这种左右对称的字符串。
输入一个字符串Str,输出Str里最长回文子串的长度。
Input
输入Str(Str的长度 <= 1000)
Output
输出最长回文子串的长度L。
Input示例
daabaac
Output示例
5
数据很小暴力,开始不知道为什么错,明明没有错误,原来数组开小了=.=
<span style="font-size:18px;">#include<cstdio> #include<cstring> char str[12000],s[12000]; int main() { while(~scanf("%s",str)) { int i,j,max=1,temp,len=strlen(str); for(i=len;i>=1;--i) { s[i*2+1]='#'; s[i*2]=str[i-1]; } s[0]=s[1]='#'; len=strlen(s); for(i=2;i<len;++i) { j=1; while(s[i-j]==s[i+j]&&i-j>=1&&i+j<len) ++j; temp=(2*j-1)/2; if(temp>max) max=temp; } printf("%d\n",max); } return 0; }</span>