bugs.cpp
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
char buf[2][2000002];
char tbuf[1002];
bool cutBugs(char *d, const char *s, const char *t) {
bool result = false;
int sp = 0;
int dp = 0;
int tp = 0;
for (sp = 0; s[sp]; sp++) {
if (!t[tp]) {
dp -= tp;
tp = 0;
result = true;
}
if (tp && s[sp] == t[tp])
tp++;
else
tp = s[sp] == t[0];
d[dp++] = s[sp];
}
if (!t[tp]) {
dp -= tp;
tp = 0;
result = true;
}
d[dp] = 0;
return result;
}
int main(int argc, char** argv) {
int lines;
while (scanf("%d %s", &lines, tbuf) == 2) {
getchar();
for (int i = 0; i < lines; i++) {
cin.getline(buf[0], 2000001);
for (bool a = false; cutBugs(buf[!a], buf[a], tbuf); a = !a);
cout << buf[0] << endl;
}
}
return 0;
}