You're Given a String...

Problem Link

 1 /*
 2 题目大意:
 3 输入一串长度不超100字符串 ,计算最长重复序列的长度 
 4 思路:暴力即可 
 5 */ 
 6 #include <iostream>
 7 #include<cmath>
 8 #include<cstring>
 9 #include<cstdio>
10 //#define LOCAL
11 using namespace std;
12 
13 int main()
14 {
15     #ifdef LOCAL
16     freopen("input.txt","r",stdin);
17     freopen("output.txt","w",stdout);
18 
19     #endif
20     char s[105];
21     while(cin >> s)
22     {
23         int len = strlen(s);
24         int step = 0; int maxx = 0;
25         // 遍历字符串,心委的代码真心赞,仅使用两层循环 
26         for(int i=0; i<len; i++)
27         {
28             for(int j=i+1; j<len; j++)
29             {
30                 step=0;
31                 if(s[i]==s[j])
32                 {
33                     while(s[i+step] == s[j+step]) step++;
34                     if(step > maxx)maxx=step; // 更新子序列长度 
35                 }
36             }
37     }
38     cout<<maxx;
39     }
40 
41     return 0;
42 }

 

posted @ 2015-03-06 14:56  constructora  阅读(171)  评论(0编辑  收藏  举报