Cod sursă (job #416530)
Utilizator |
|
IP | ascuns |
---|---|---|---|
Problemă | Bart (clasele 9-10) | Compilator | cpp | 0,49 kb |
Rundă | concurs_6_10 | Status | evaluat |
Dată | 6 ian. 2019 16:39:51 | Scor | 20 |
#include <fstream>
#include <string.h>
using namespace std;
ifstream fin ("bart.in");
ofstream fout ("bart.out");
int i, cnt, KMP[500005];
char str[500005];
int main()
{
fin.getline(str + 1, 500005);
for(i = 2; i <= strlen(str + 1); i++) {
while(cnt > 0 && str[i] != str[cnt + 1]) cnt = KMP[cnt];
if(str[i] == str[cnt + 1]) cnt++;
KMP[i] = cnt;
}
for(i = 1; i <= strlen(str + 1) - KMP[strlen(str + 1)]; i++) fout << str[i];
return 0;
}