bugs.c
#include <stdio.h>
#include <string.h>
int AutomatEsc[1000];
char Vstup[3000000];
char Bugr[2000];
int main() {
int T;
char *Bug;
int BL,VL;
int Pos;
int AP;
int OldAP;
int i;
char c;
int WO;
while (scanf("%d",&T
) == 1) { Bug = Bugr+1;
AutomatEsc[0] = -1;
AP = -1;
for (Pos = 1;Pos < BL;Pos++) {
AP++;
while ((*(Bug+AP) != *(Bug+Pos)) && (AP>=0)) {
AP = AutomatEsc[AP];
};
AutomatEsc[Pos]=AP;
};
//for (Pos = 0;Pos < BL;Pos++) printf("%d ",AutomatEsc[Pos]);
//printf("\n");
while (T-->0) {
AP = -1;
for (Pos = 0;Pos < VL;Pos++) {
c = *(Vstup+Pos);
OldAP = AP;
while ((*(Bug+AP+1) != c) && (AP >=0)) {
//printf("ESC %d %d\n",AP,AutomatEsc[AP]);
AP = AutomatEsc[AP];
};
if (AP == -1) {
if (c == *Bug) AP = 0;
} else AP++;
//printf("%d %d %c-",AP,OldAP,c);
if (AP == BL-1) {
AP = -1;
} else {
if (OldAP != -1) {
WO = OldAP - AP;
if (AP == -1) WO--;
for (i
=0;i
<=WO
;i
++) printf("%c",*(Bug
+i
)); };
};
//printf("-\n");
};
for (i
=0;i
<=AP
;i
++) printf("%c",*(Bug
+i
)); };
};
return 0;
};