Cod sursa(job #1316516)

Utilizator seba1234Seba Stanici seba1234 Data 13 ianuarie 2015 21:26:41
Problema Substr Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <string.h>
#include <fstream>

using namespace std;

int main()
{
    int n,k;
    char a[16384],salv[16384];
    int l=0,h=0,sv;
    char b[8192],*p,*q;
    ifstream fin("substr.in");
    fin >> n >> k >> a; k--; sv=k;
    ofstream fout("substr.out");
    strcpy(salv,a);
    for (int i=2;i<=n/2;i++)
    {
        k=sv;
        for (int j=0;j<=n-i;j++)
        {
            l=0; p=a;
            strncpy(b,p+j,i);
            while (strstr(p,b)) { l++;
                q=strstr(p,b);
                strcpy(q,q+i);
                p=q;
            }
            strcpy(a,salv); p=a;
            if (k<l) { k=l; h=strlen(b); }
        }
    }
    fout << h;
}