Pagini recente » Cod sursa (job #304468) | Cod sursa (job #1398545) | Cod sursa (job #750638) | Cod sursa (job #798814) | Cod sursa (job #1260250)
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,m,i,j;
char ch[16399];
int cc(char s){
if( s >= 'A' )
if( s >= 'a' ) return s - 'a';
else return s - 'A' + 26;
else return s - '0' + 52;
}
struct trie{
int cnt;
trie *fiu[62];
trie(){
memset(fiu,0,sizeof(fiu));
cnt = 0;
}
};
trie *t = new trie,*tmp;
int main()
{
freopen("substr.in" ,"r", stdin);
freopen("substr.out","w", stdout);
scanf("%d %d\n",&n,&m);
scanf("%s",ch);
int mmax=-6;
int ccc;
for(i=0;i<n;++i){
tmp = t;
j=0;
while( true ){
tmp->cnt++;
if( ch[i+j] == '\0' ){
break;
}
if( tmp->cnt >= m )
if( mmax < j ) mmax = j;
ccc = cc( ch[i+j] );
if( tmp->fiu[ ccc] == 0){
tmp->fiu[ ccc ] = new trie;
}
tmp = tmp->fiu[ ccc ];
++j;
}
}
printf("%d\n",mmax);
return 0;
}