51Nod 1088 最长回文子串
2017-07-17 11:21
190 查看
1088 最长回文子串
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
收藏
取消关注
回文串是指aba、abba、cccbccc、aaaa这种左右对称的字符串。
输入一个字符串Str,输出Str里最长回文子串的长度。
Input
Output
Input示例
Output示例
相关问题
想法:从两边扩展,分为长度为奇数的回文串和偶数的回文串
代码:
#include<stdio.h>
#include<string.h>
char s[10010];
int main()
{
gets(s);
int len=strlen(s);
int i,j;
int count,maxx=-1;
for(i=0;i<len;i++)
{
count=0;
for(j=0;j<=i&&i+j<len;j++)
{
if(s[i+j]!=s[i-j])
break;
count=2*j+1;
if(maxx<count)
maxx=count;
}
count=0;
for(j=0;j<=i&&j+i+1<len;j++)
{
if(s[i+j+1]!=s[i-j])
break;
count=2*j+2;
if(maxx<count)
maxx=count;
}
}
printf("%d\n",maxx);
return 0;
}
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
收藏
取消关注
回文串是指aba、abba、cccbccc、aaaa这种左右对称的字符串。
输入一个字符串Str,输出Str里最长回文子串的长度。
Input
输入Str(Str的长度 <= 1000)
Output
输出最长回文子串的长度L。
Input示例
daabaac
Output示例
5
相关问题
想法:从两边扩展,分为长度为奇数的回文串和偶数的回文串
代码:
#include<stdio.h>
#include<string.h>
char s[10010];
int main()
{
gets(s);
int len=strlen(s);
int i,j;
int count,maxx=-1;
for(i=0;i<len;i++)
{
count=0;
for(j=0;j<=i&&i+j<len;j++)
{
if(s[i+j]!=s[i-j])
break;
count=2*j+1;
if(maxx<count)
maxx=count;
}
count=0;
for(j=0;j<=i&&j+i+1<len;j++)
{
if(s[i+j+1]!=s[i-j])
break;
count=2*j+2;
if(maxx<count)
maxx=count;
}
}
printf("%d\n",maxx);
return 0;
}
相关文章推荐
- 【51nod】1088 最长回文子串
- [51nod] 1088 最长回文子串 #Hash+二分
- 51nod 1088 最长回文子串
- 51nod 1088 最长回文子串
- 51nod 1088 最长回文子串
- 51Nod-1088-最长回文子串
- 51nod_1088 最长回文子串((Manacher算法)
- 51nod 1088 最长回文子串
- 51nod-【1088 最长回文子串】
- 51Nod-1088-最长回文子串
- 1088 最长回文子串 分类: 51nod 2015-07-20 22:09 8人阅读 评
- 51nod1089---最长回文子串 V2(51nod基础:Manacher算法)
- 51Nod - 1089 最长回文子串 V2(Manacher算法)
- 【Manacher算法】51nod 最长回文子串 V2
- 51nod-【1089 最长回文子串 V2(Manacher算法)】
- 51nod--1089 最长回文子串V2(Manacher 算法)
- 1088 最长回文子串
- 51nod_1089 最长回文子串 V2(Manacher算法)
- 51nod-【hihocoder #1032 : 最长回文子串】
- 51nod 1089 最长回文子串 V2(Manacher算法)