Source code for submission s1147

Go to diff to previous submission

bug.cpp

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int q, ind;
  5. char bug[1200];
  6. char line[2000009];
  7. char tmpLine[10000];
  8. int c;
  9.  
  10. bool jeVslove()
  11. {
  12. int len = strlen(bug);
  13.  
  14. if(ind < len)
  15. return false;
  16.  
  17. for(int i = len-1; i >= 0; i--)
  18. {
  19. if(bug[i] != line[ind-len+i])
  20. {
  21. return false;
  22. }
  23. }
  24.  
  25. return true;
  26. }
  27.  
  28. int main()
  29. {
  30. while(fgets(tmpLine, 9999, stdin) != NULL)
  31. {
  32. sscanf(tmpLine, "%d %s", &q, bug);
  33. //printf("%d", q);
  34. for(int i = 0; i<q; i++)
  35. {
  36. ind = 0;
  37. while(true)
  38. {
  39. c = getchar();
  40. //printf("%c", c);
  41.  
  42. if(c != EOF)
  43. {
  44. line[ind] = c;
  45. ind++;
  46. }
  47.  
  48. if(c == '\n' || c == EOF)
  49. {
  50. line[ind] = 0;
  51. //printf("%s", line);
  52. fputs(line, stdout);
  53. break;
  54. }
  55.  
  56. if(jeVslove())
  57. {
  58. ind -= strlen(bug);
  59. }
  60.  
  61. }
  62. }
  63. }
  64.  
  65.  
  66. return 0;
  67. }

Diff to submission s1093

bug.cpp

--- c4.s1093.cteam122.bugs.cpp.0.bug.cpp
+++ c4.s1147.cteam122.bugs.cpp.0.bug.cpp
@@ -6,5 +6,5 @@
 char line[2000009];
 char tmpLine[10000];
-char c;
+int c;
 
 bool jeVslove()
@@ -39,13 +39,18 @@
         c = getchar();
         //printf("%c", c);
-        if(c == '\n')
+        
+        if(c != EOF)
         {
-          line[ind] = 0;        
-          printf("%s\n", line);
+          line[ind] = c;
+          ind++;
+        }
+        
+        if(c == '\n' || c == EOF)
+        {
+          line[ind] = 0;
+          //printf("%s", line); 
+          fputs(line, stdout);
           break;
         }
-          
-        line[ind] = c;
-        ind++;
         
         if(jeVslove())