codeforences 29A
来源:互联网 发布:王伟看懂世界格局知乎 编辑:程序博客网 时间:2024/06/06 01:49
A - You're Given a String... p
Time Limit: 2000MS Memory Limit: 262144K 64bit IO Format: %I64d & %I64u
[Submit]
Description
You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).
Input
The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.
Output
Output one number — length of the longest substring that can be met in the string at least twice.
Sample Input
Input
abcd
Output
0
Input
ababa
Output
3
Input
zzz
Output
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;}
0 0
- codeforences 29A
- A. Winner Codeforences
- Codeforences #339 A. Link/Cut Tree
- Codeforences #297 div2 (A,B,C,D,E)
- B. Center Alignment codeforences
- Codeforences B. Island Puzzle
- Codeforences #309 B (div2)
- Codeforences #309 C(div2)
- Codeforences #334 C(div2)
- Codeforences #345 C
- Codeforences Educational Round 11
- Codeforences Round #349 (div2)
- Codeforences #351 VK CUP
- Codeforences #368 部分题解
- Codeforences 15 E triangles
- Codeforences 17C Balance
- Codeforences 17E Palisection
- Codeforences 23D Tetragon
- c
- 调用库函数进行的qsort快速排序
- POJ 1742
- c++ primer阅读笔记-12章-4
- 动手学MFC之九——带上绘图搞定FlappyBird(上)
- codeforences 29A
- 数字证书的一些基本概念
- 【顺时针打印矩阵】
- shell——cat,find,xargs,tr,sort,grep
- 独角戏
- 003
- Android Mms专题之:信息发送流程
- 华为笔试之字符串旋转
- Oracle sqlplus 常用设置