Cod sursă (job #377145)

Utilizator avatar Dorde662 Dorde E Dorde662 IP ascuns
Problemă Bart (clasele 9-10) Compilator cpp | 0.61 kb
Rundă Arhiva de probleme Status evaluat
Dată 13 apr. 2018 22:51:15 Scor 100
#include <bits/stdc++.h>
using namespace std;
char const in [] = "bart.in";
char const out [] = "bart.out";
int const NM = 5000007;
char v [NM];
int st [NM];
ifstream f (in);
ofstream g (out);
int main()
{
    int n , atpos = 0 , i , att = 1;
    f >> v ;
    n = strlen (v );
    for(i = 1 ; i <= n ; ++ i)
    {
        while (atpos && (v [atpos] != v [att]))
        {
            atpos = st [atpos - 1];
        }
        if (v [atpos] == v [att])
            ++ atpos;
        st [att ++ ] = atpos;
    }
    v [n - st[n - 1]] = '\0';
    g << v ;
    f.close();
    g.close();
    return 0;
}