Source code for submission s1235

Go to diff to previous submission

bug.cpp

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

Diff to submission s1147

bug.cpp

--- c4.s1147.cteam122.bugs.cpp.0.bug.cpp
+++ c4.s1235.cteam122.bugs.cpp.0.bug.cpp
@@ -2,8 +2,9 @@
 #include <string.h>
 
-int q, ind;
+int q, ind, pozicia;
 char bug[1200];
 char line[2000009];
-char tmpLine[10000];
+char readed[2000009];
+char tmpLine[1500];
 int c;
 
@@ -28,5 +29,5 @@
 int main()
 {
-  while(fgets(tmpLine, 9999, stdin) != NULL)
+  while(fgets(tmpLine, 1300, stdin) != NULL)
   {
     sscanf(tmpLine, "%d %s", &q, bug);
@@ -34,15 +35,18 @@
     for(int i = 0; i<q; i++)
     {
+      pozicia = 0;
+      
+      if(fgets(readed, 2000005, stdin) == NULL)
+        break;
+          
       ind = 0;
       while(true)
       {
-        c = getchar();
+        c = readed[pozicia];
+        pozicia++;
         //printf("%c", c);
         
-        if(c != EOF)
-        {
-          line[ind] = c;
-          ind++;
-        }
+        line[ind] = c;
+        ind++;
         
         if(c == '\n' || c == EOF)