Cod sursă (job #94602)

Utilizator avatar andi andrei draghici andi IP ascuns
Problemă Bart (clasele 9-10) Compilator cpp | 0,73 kb
Rundă Tema 8 clasele 9-10 2014/15 Status evaluat
Dată 2 dec. 2014 22:28:29 Scor 66
#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;i++)
    {
        if(jmen[i]>max)
            max=jmen[i];
    }
    ras=m-max;
    for(i=0;i<ras;i++)
        fprintf(out,"%c",p[i]);
    return 0;
}