Cod sursa(job #1316481)

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

using namespace std;

int n,k;
char a[16384],salv[16384];

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