Cod sursă (job #710418)

Utilizator avatar tomaariciu Ariciu Toma tomaariciu IP ascuns
Problemă Bart (clasele 9-10) Compilator cpp-32 | 0,52 kb
Rundă Arhiva de probleme Status evaluat
Dată 23 mar. 2023 10:40:05 Scor 70
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5;
int pi[N];
int main()
{
    ifstream fin("bart.in");
    ofstream fout("bart.out");
    string str;
    fin >> str;
    int n = str.size() - 1;
    for(int i = 1; i <= n; i++)
    {
        int k = pi[i - 1];
        while(k && str[k] != str[i])
            k = pi[k];
        if(str[k] == str[i])
            k++;
        pi[i] = k;
    }
    int period = n - pi[n];
    for(int i = 0; i <= period; i++)
        fout << str[i];
    return 0;
}