Cod sursa(job #1108198)

Utilizator andreiiiiPopa Andrei andreiiii Data 15 februarie 2014 14:43:26
Problema Substr Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <algorithm>
#include <fstream>
#include <cstring>

using namespace std;

const int N=17000;

ifstream fin("substr.in");
ofstream fout("substr.out");

char a[N], *b[N];

struct comp
{
    bool operator()(const char *r, const char *t)
    {
        return strcmp(r, t)<0;
    }
};

int main()
{
    int n, k, i, sol=0, s;
    char *p1, *p2;
    fin>>n>>k; fin.get();
    fin.getline(a, N);
    for(i=0;i<n;i++) b[i]=a+i;
    sort(b, b+n, comp());
    for(i=0;i+k<=n;i++)
    {
        for(p1=b[i], p2=b[i+k-1], s=0;*p1&&*p2&&*p1==*p2;s++, p1++, p2++);
        sol=max(sol, s);
    }
    fout<<sol<<"\n";
    fin.close();
    fout.close();
}