Cod sursă (job #377521)

Utilizator avatar RaduN PinguLinux RaduN IP ascuns
Problemă Bart (clasele 9-10) Compilator cpp | 0,49 kb
Rundă Arhiva de probleme Status evaluat
Dată 18 apr. 2018 13:47:58 Scor 20
#include <fstream>
#include <string>
using namespace std;
ifstream f("bart.in");
ofstream g("bart.out");
string s;
int repet[500002];
int main() {
    int n, curent=0, i, pos=1;
    f>>s;
    n=s.size();
    for(i=1; i<=n; i++) {
        while (curent && (s[curent]!=s[pos])) {
            curent=repet[curent-1];
        }
        if (s[curent]==s[pos]){
            curent++;
        }
        repet[pos++]=curent;
    }
    s[n-repet[n-1]]='\0';
    g<<s;
    return 0;
}