bugs.cpp
#include <cstdio>
#include <cstring>
bool tests(char *a, char *b) //true=nalezeno
{
int i;
for (i=0; (a[i]!='\0')&&(b[i]!='\0'); i++)
{
//printf("%c = %c\n" ,a[i],b[i]);
if(a[i]!=b[i])
{
return false;
}
}
if(b[i]!='\0')
return false;
return true;
}
int main()
{
char bug[1002];
int lines;
while (scanf("%d %s",&lines,bug)==2)
{
int buglen=strlen(bug);
bool firstrun=true;
for(int ln=0;ln<lines;ln++)
{
char line[2000002],*lptr;
fgets(line,2000002,stdin);
if(firstrun && line[0]=='\n')
{
firstrun=false;
fgets(line,2000002,stdin);
}
bool found=false;
do //dokud je na radku najden bug
{
found=false;
int l,o=0;
for(l=0; line[l]!='\0'; l++)
{
lptr=line+l;
//if(strncmp(lptr,bug,buglen)==0)
if(tests(lptr,bug)==true)
{
found=true;
l+=buglen-1;
//printf("repete\n");
}
else
{
line[o]=line[l];
o++;
}
}
line[o]=0;
//putchar('w');
}while(found);
printf("%s",line);
}
}
return 0;
}