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 }

 

转载于:https://www.cnblogs.com/construtora/p/4318249.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值