Solve equation
2016-03-27 14:54
260 查看
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
Output
Input
Output
Input
Output
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
</pre><pre name="code" class="cpp">#include<iostream> #include<cstring> #include<algorithm> #include<map> #include<cstdio> #include<string> using namespace std; map<string,int>num; int main() { string s,name; int i,j,k,n; cin>>s; n=s.size(); for(k=1;k<=n;k++) { for(i=0;i+k<=n;i++) { name=""; for(j=i;j<i+k;j++) { name=name+s[j]; } num[name]++; if(num[name]>1) break; } if(i+k>n) break; } cout<<k-1<<endl; return 0; }
相关文章推荐
- 操作系统内存管理
- 十五个数的排序
- linux编译安装LAMP
- 多线程实现多图片下载1
- hdu 3371(kruskal)
- HDU 5651 逆元
- VC++6.0 unexpected end of file while looking for precompiled header directive
- 安卓手机屏幕基础解析
- Java可变参数方法的重载实例
- VS错误error C1083 和XX.pch错误
- C#全局键盘检测GetAsyncKeyState
- 操作系统内存页面置换算法
- Scrum 之 四大支柱和价值观
- 日志分析项目
- 成绩排名——华为上机笔试题
- 购物商城shopping连载(1)
- form表单提交之前推断
- Linux CentOS6系统安装最新版本Node.js环境及相关文件配置
- 面试感悟----一名3年工作经验的程序员应该具备的技能
- RoaringBitmap简析