Source code for submission s1136

bugs.cpp

  1. #include <cstdio>
  2. #include <cstring>
  3.  
  4. bool tests(char *a, char *b) //true=nalezeno
  5. {
  6. int i;
  7. for (i=0; (a[i]!='\0')&&(b[i]!='\0'); i++)
  8. {
  9. //printf("%c = %c\n" ,a[i],b[i]);
  10. if(a[i]!=b[i])
  11. {
  12. return false;
  13. }
  14. }
  15.  
  16. if(b[i]!='\0')
  17. return false;
  18. return true;
  19. }
  20.  
  21.  
  22. int main()
  23. {
  24. char bug[1002];
  25. int lines;
  26. while (scanf("%d %s",&lines,bug)==2)
  27. {
  28. int buglen=strlen(bug);
  29.  
  30. bool firstrun=true;
  31.  
  32. for(int ln=0;ln<lines;ln++)
  33. {
  34.  
  35. char line[2000002],*lptr;
  36.  
  37. fgets(line,2000002,stdin);
  38.  
  39. if(firstrun && line[0]=='\n')
  40. {
  41. firstrun=false;
  42. fgets(line,2000002,stdin);
  43. }
  44.  
  45.  
  46. bool found=false;
  47. do //dokud je na radku najden bug
  48. {
  49. found=false;
  50.  
  51. int l,o=0;
  52.  
  53. for(l=0; line[l]!='\0'; l++)
  54. {
  55.  
  56. lptr=line+l;
  57.  
  58. //if(strncmp(lptr,bug,buglen)==0)
  59. if(tests(lptr,bug)==true)
  60. {
  61. found=true;
  62. l+=buglen-1;
  63. //printf("repete\n");
  64. }
  65. else
  66. {
  67. line[o]=line[l];
  68. o++;
  69. }
  70. }
  71. line[o]=0;
  72.  
  73. //putchar('w');
  74.  
  75. }while(found);
  76.  
  77. printf("%s",line);
  78. }
  79. }
  80.  
  81. return 0;
  82. }
  83.