You're Given a String...
2024-08-29 13:27:13
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.
Example
Input
abcd
Output
0
Input
ababa
Output
3
Input
zzz
Output
2
找重复出现至少一次的最大子串长度
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#define Max 1001
using namespace std;
char s[]; int main()
{
cin>>s;
int d = ;
for(int i = ;i < strlen(s) - ;i ++)
{
for(int j = i + ;j < strlen(s);j ++)
{
int cnt = ;
while(j + cnt <strlen(s)&&s[i + cnt] == s[j + cnt])cnt ++;
if(d < cnt)d = cnt;
}
}
cout<<d<<endl;
}
最新文章
- java-JDBC从数据库中读取数据并进行日期民族男女的转换
- document对象
- 141. Linked List Cycle
- ubuntun pptpd
- mysql查看日志
- Windows下tuxedo配置
- 团体程序设计天梯赛-练习集L1-007. 念数字
- Subversion安装和使用
- Hive - 建表和加载数据指令小结 以及使用Load data指令的注意事项
- Objective-C中的内存管理——手动内存管理
- POJ 1064 Cable master(二分查找+精度)(神坑题)
- java.text.NumberFormat使用方法
- Redis学习-发布/订阅
- [SCOI 2016]美味
- Systemd 教程
- Django(十五)Form组件
- JSP 性能优化
- DOM常用事件绑定方式与实例
- JS高级-String-正则表达式:
- ECMAScript 6 Promise 对象