3901 - Editor Asia - Seoul - 2007/2008
来源:互联网 发布:中超球员数据 编辑:程序博客网 时间:2024/06/05 15:50
Asia - Seoul - 2007/2008PDF Submit Ranking
Mr. Kim is a professional programmer. Recently he wants to design a new editor which has as many functions as possible. Most editors support a simple search function that finds one occurrence (or all occurrences successively) of a query pattern string in the text.
He observed that the search function in commercial editors does nothing if no query pattern is given. His idea of a new search function regards each substring of the given text as a query pattern string itself and his new function finds another occurrence in the text. The problem is that there can be occurrences of many substrings in the text. So, Mr. Kim decides that the new function finds only occurrences of the longest substring in the text in order to remedy the problem. A formal definition of the search function is as follows:
Given a text string S , find the longest substring in text string S such that the substring appears at least twice. The two occurrences are allowed to overlap.
Input
Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. For each test case, a text string S is given in one line. For every string, the length is less than or equal to 5,000 and the alphabet is the set of lowercase English characters.
Output
Your program is to write to standard output. Print exactly one line for each test case. Print the length of the longest substring in text string S such that the substring appears at least twice.
Sample Input
3 abcdefghikjlmn abcabcabc abcdabcabb
Sample Output
0 6 3
Seoul 2007-2008
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
vector<int> pre[26];
string str;
cin>>str;
int len=str.size();
for(int i=0;i<len;i++) pre[str[i]-'a'].push_back(i);
int maxn=0;
for(int i=0;i<26;i++)
{
int l=pre[i].size();
if(l<=1) continue;
for(int j=0;j<l;j++)
{
for(int k=j+1;k<l;k++)
{
int cnt=0;
int g=pre[i][j],h=pre[i][k];
for(int c=0;h+c<len;c++,cnt++) if(str[g+c]!=str[h+c]) break;
if(cnt>maxn) maxn=cnt;
}
}
}
printf("%d/n",maxn);
}
return 0;
}
- 3901 - Editor Asia - Seoul - 2007/2008
- 3903 - PHONE Asia - Seoul - 2007/2008
- 3900 - Molar mass Asia - Seoul - 2007/2008
- 3904 - Tile Code Asia - Seoul - 2007/2008
- Asia - Seoul - 2007/2008 UVA 3902 Network
- newwork Seoul 2007
- Meteor Seoul 2007
- Processor Seoul 2008
- UVA Live 4732 Jinhan 带权并查集 2009 Asia Seoul Regional
- 网络(Network,Seoul 2007,LA 3902)
- 网络 network,Seoul 2007 LA3902 解题感想
- Seoul 2007 Meteor 流星 ,LA 3905
- 分子量(Molar Counting, ACM/ICPC Seoul 2007)
- UVaLive(LA) 3902 Network,Seoul 2007
- [Molar Mass, ACM/ICPC Seoul 2007, UVA1586]
- 处理器(Processor,Seoul 2008,LA 4254)
- Seoul 2007 / UVa 1398 Meteor (排序&线性扫描)
- Molar Mass, ACM/ICPC Seoul 2007, UVa 1586
- Linux文件查找命令find,xargs详述
- Poj1159——最长公共子序列
- 字符画生成器 修正版 v1.1
- Poj1458——最长公共子序列
- 最长上升子序列
- 3901 - Editor Asia - Seoul - 2007/2008
- hdu1280——hash
- 一个Java程序员应该掌握的10项技能
- NIO监听网络通信
- DIV弹出层练习(一) ------------------ 用js实现在超链接的下方弹出div层
- ubuntu 更新源
- Android资料
- xoops简介
- 一招废掉所有木马