You're Given a String... CodeForces
来源:互联网 发布:剑灵捏脸数据分享 编辑:程序博客网 时间:2024/04/27 23:48
You're Given a String...
CodeForces - 23A
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).
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 one number — length of the longest substring that can be met in the string at least twice.
Input
abcd
Output
0
Input
ababa
Output
3
Input
zzz
Output
2
#include <iostream>#include <cstdio>#include <cstring>#include <string>using namespace std;int main(){ string s; cin >> s; int i,j,k; int longest = 0; for(i = 0; i < s.length(); i++){ for(j = i; j < s.length(); j++){//选择出子串i到j int index = i; int cnt = 0; for(k = 0; k < s.length(); k++){//从头比较 int q = 0; int flag = 1; while(q < (j-i+1)){//从k起点,然后往后长度为j-i+1,比较已经选出的子串,比较完后起始点挪到下一个 if(s[i+q] != s[k+q]){ flag = 0; break; } else q++; } if(flag) cnt++; } if(cnt >= 2){ longest = max(longest,j-i+1); } } } cout << longest << endl; return 0;}
阅读全文
0 0
- You're Given a String... CodeForces
- codeforces 23A. You're Given a String...
- CodeForces 23A You're Given a String...
- CodeForces 23A You're Given a String... (简单题)
- CodeForces 23A-You're Given a String...
- You're Given a String...
- A. You're Given a String...
- A - You‘re Given a String
- A. You\'re Given a String...
- CodeForces 23A You're Given a String...(字符串处理)
- 【strstr】#23 A. You're Given a String...
- You are given a tetrahedron.
- You’re given an array containing both positive and negative integers and required to find the sub-a
- How do you remove the duplicate characters in a given string without using any additional buffer.
- CareerCup Given a dictionary, how would you add spaces in this string
- reverse a given string StringTokenizer
- Why You’re a Bad PHP Programmer
- So You’re Coming to a Career Fair
- Java提高篇(三四)-----fail-fast机制
- JAVA WEB项目中的路径问题。
- K
- 使用Mybatis-Generator自动生成代码
- CodeChef:Desik And Divisors(数学 & 二分 & 思维)
- You're Given a String... CodeForces
- [Unity]如果AssetStore的下载无效怎么办
- [hdu1599]find the mincost route
- 数据库
- 网络请求数据之XUtils和Volley
- VS2013+QT5.8.0 过程记录
- VS2013+QT5.8.0 过程记录
- hduoj 2010
- oracle语句管理表_DDL