Cod sursă (job #378261)
Utilizator |
|
IP | ascuns |
---|---|---|---|
Problemă | Bart (clasele 9-10) | Compilator | cpp | 0,51 kb |
Rundă | Arhiva de probleme | Status | evaluat |
Dată | 25 apr. 2018 08:31:52 | Scor | 100 |
#include <fstream>
#include <cstring>
using namespace std;
ifstream cin("bart.in");
ofstream cout("bart.out");
char ch[500005];
int prefix[500005];
int main()
{
cin>>(ch+1);
int p = 0, cuv = strlen(ch+1);
for(int i = 2; i <= cuv; i ++)
{
while(p && ch[i] != ch[p + 1])
p = prefix[p];
if(ch[i] == ch[p + 1])
p++;
prefix[i] = p;
}
for(int i = 1; i <= cuv - prefix[cuv]; i ++)
cout << ch[i];
return 0;
}