codeforences 29A
2014-04-08 20:10
501 查看
A - You're Given a String... p
abcdOutput 0Input ababaOutput 3Input zzzOutput 2 这个题目的意思是说找出其子串中最大循环的个数,我很惭愧,在kmmm的这个例子里,应该是2,可我一开始认为是0.是子串,可以包含没有的,所以不可以用kmp,因为kmp数组求出的是前面的最大匹配数目,这个时候有人可能会问假如遍历next[],数组求出最大的不就行了吗,其实不行的,因为在aaa,中,next[]最大是3,而其实是2的,所以暴力比较是个不错的法子。 #include<iostream>#include<cstdio>#include<cstring>using namespace std;char s[120];int main(){int i,j,k;int max;while(scanf("%s",s)!=EOF){max=-100;int l=strlen(s);for(i=0;i<l;i++){for(j=i+1;j<l;j++){k=0;while(s[i+k]==s[j+k]){k++;}if(max<k)max=k;}}printf("%d\n",max);}return 0;} |
相关文章推荐
- String.intern
- 文件遍历排序函数
- Prototype源码浅析 String部分(二)
- 浅谈C++中的string 类型占几个字节
- 标准C++类string的Copy-On-Write技术
- 一个目录遍历函数
- PHP STRING 陷阱原理说明
- c#中 String和string的区别介绍
- asp.net String.IsNullOrEmpty 方法
- javascript Split方法,indexOf方法、lastIndexOf 方法和substring 方法
- javascript String 对象
- mysql输出数据赋给js变量报unterminated string literal错误原因
- Javascript的数组与字典用法与遍历对象的属性技巧
- IE8下String的Trim()方法失效的解决方法
- jQuery 遍历-nextUntil()方法以及prevUntil()方法的使用介绍
- jQuery代码优化 遍历篇
- javascript String 的扩展方法集合
- JS中的substring和substr函数的区别说明
- js substr、substring和slice使用说明小记
- js中substring和substr的详细介绍与用法