Cod sursă (job #94603)

Utilizator avatar andi andrei draghici andi IP ascuns
Problemă Bart (clasele 9-10) Compilator cpp | 0,64 kb
Rundă Tema 8 clasele 9-10 2014/15 Status evaluat
Dată 2 dec. 2014 22:40:05 Scor 90
#include <cstdio>

using namespace std;
const int N=500000;
char p[N+1];
int jmen[N+1],m,n;
void preprocesare()
{
    int k,q;
    jmen[0]=0;
    k=0;
    for (q=1;q<m;q++)
    {
        while ((k > 0) && (p[k] != p[q]))
            k = jmen[k - 1];
        if (p[k] == p[q])
            k++;
        jmen[q] = k;
    }
}
int main()
{
    FILE *in,*out;
    in=fopen("bart.in","r");
    out=fopen("bart.out","w");
    int i,j,ras=0,ok=0,max=0;
    fscanf(in,"%s",&p);
    i=0;
    while(p[i]!=0)
        i++;
    m=i;
    preprocesare();
    for(i=0;i<m-jmen[m-1];i++)
        fprintf(out,"%c",p[i]);
    return 0;
}