51Nod 1088 最长回文子串
来源:互联网 发布:海软订货系统源码 编辑:程序博客网 时间:2024/05/23 17:43
1088 最长回文子串
基准时间限制: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;
}
#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;
}
阅读全文
0 0
- 51nod 1088 最长回文子串
- 51nod 1088 最长回文子串
- 51nod 1088 最长回文子串
- 51nod-【1088 最长回文子串】
- 51nod 1088 最长回文子串
- 【51nod】1088 最长回文子串
- 51Nod 1088 最长回文子串
- 51Nod-1088-最长回文子串
- 51nod 1088 最长回文子串
- 51Nod 1088 最长回文子串
- 51Nod-1088-最长回文子串
- 51nod--1088 最长回文子串(连续!)
- 51nod 最长回文子串 V2(Manacher算法)
- 51nod-【hihocoder #1032 : 最长回文子串】
- nod-1089-最长回文子串 V2
- 51Nod 1088 最长回文串
- 51nod oj 1088 1089 最长回文子串 【Manacher算法】
- 1088 最长回文子串
- Querydsl 手动构建Predicate
- opencv安装之前的准备知识
- service不是内部或者外部命令
- 连涨几个月后 香港楼市增速或将放缓
- Kubernetes初探:原理及实践应用
- 51Nod 1088 最长回文子串
- 【ZOJ2112】Dynamic Ranking(主席树)
- 《KyLin学习理解》-02-KyLin的网页界面使用
- Educational Codeforces Round 23 817E. Choosing The Commander 字典树 位运算
- Hrbust 1401 九连环【递推+矩阵快速幂】
- SQLite基础知识
- 对象的生命历程
- idea里web.xml中的classpath:xml/applicationContext.xml文件路径找不到
- 项目流程