Source code for submission s1273

Go to diff to previous submission

bug.cpp

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

Diff to submission s1235

bug.cpp

--- c4.s1235.cteam122.bugs.cpp.0.bug.cpp
+++ c4.s1273.cteam122.bugs.cpp.0.bug.cpp
@@ -2,15 +2,12 @@
 #include <string.h>
 
-int q, ind, pozicia;
+int q, ind, len;
 char bug[1200];
 char line[2000009];
-char readed[2000009];
-char tmpLine[1500];
+char tmpLine[10000];
 int c;
 
 bool jeVslove()
-{
-    int len = strlen(bug);
-    
+{    
     if(ind < len)
       return false;
@@ -29,24 +26,22 @@
 int main()
 {
-  while(fgets(tmpLine, 1300, stdin) != NULL)
+  while(fgets(tmpLine, 9999, stdin) != NULL)
   {
     sscanf(tmpLine, "%d %s", &q, bug);
+    len = strlen(bug);
     //printf("%d", q);
     for(int i = 0; i<q; i++)
     {
-      pozicia = 0;
-      
-      if(fgets(readed, 2000005, stdin) == NULL)
-        break;
-          
       ind = 0;
       while(true)
       {
-        c = readed[pozicia];
-        pozicia++;
+        c = getchar();
         //printf("%c", c);
         
-        line[ind] = c;
-        ind++;
+        if(c != EOF)
+        {
+          line[ind] = c;
+          ind++;
+        }
         
         if(c == '\n' || c == EOF)
@@ -60,5 +55,5 @@
         if(jeVslove())
         {
-          ind -= strlen(bug);
+          ind -= len;
         }