Cod sursa(job #1260250)

Utilizator bogdanpaunFMI Paun Bogdan Gabriel bogdanpaun Data 11 noiembrie 2014 01:23:18
Problema Substr Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#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;
}