bugs.cpp
#include <cstdio>
#include <cstring>
using namespace std;
#define NULLCHAR 2
inline bool match_delete(const int index, const int B_len, const char B[], char LINE[]){
int b=0, l = index;
while (b < B_len){
while (LINE[l] == NULLCHAR){
l++;
}
if(B[b] != LINE[l]){
return false;
}
b++;
l++;
}
for (int i = index; i < l; i++){
LINE[i] = NULLCHAR;
}
return true;
}
int main()
{
int N;
char B[1010];
char LINE[2000010];
while (scanf("%d %1005s", &N, B) == 2) {
gets(LINE);
int B_len = strlen(B);
for (int row = 0; row < N; row++) {
gets(LINE);
int index = 0;
while (LINE[index] != '\0') {
if (LINE[index] == B[0]){
if (match_delete(index, B_len, B, LINE)){
index -= B_len;
if (index < 0){
index = 0;
}
}
}
index++;
}
index = 0;
while (LINE[index] != '\0'){
if (LINE[index] != NULLCHAR){
printf("%c", LINE[index]);
}
index++;
}
printf("\n");
}
}
return 0;
}