Source code for submission s1185

Go to diff to previous submission

bugs.cpp

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "string.h"
  5.  
  6. int zas[3000000];
  7. char vzor[5000];
  8. char text[3000000];
  9. char vystup[3000000];
  10. char vystup_R[3000000];
  11. char line[10000];
  12.  
  13. int main()
  14. {
  15. int n;
  16.  
  17. while ( scanf("%i ", &n) == 1)
  18. {
  19. gets(vzor);
  20.  
  21. int vlen = strlen(vzor);
  22.  
  23.  
  24. for(int l = 0; l < n; l++ )
  25. {
  26. int vystup_p = 0;
  27.  
  28. int vr = 0; // vrchol zas
  29. int posl_vypsany = -1;
  30.  
  31.  
  32. gets(text);
  33.  
  34. int p = 0;
  35. int pvz = 0;
  36.  
  37. while(text[p] != '\0')
  38. {
  39. //printf("%c\n",text[p]);
  40.  
  41. if (text[p] == vzor[pvz]) // vzor pasuje
  42. {
  43. pvz++;
  44. if (pvz == vlen)
  45. {
  46. if (vr == 0)
  47. {
  48. pvz = 0;
  49. posl_vypsany = p;
  50. }
  51. else
  52. {
  53. pvz= zas[vr-1];
  54. vr --;
  55. }
  56. }
  57. }
  58. else
  59. {
  60. if (pvz > 0 )
  61. {
  62. if (text[p] == vzor[0])
  63. {
  64. zas[vr] = pvz;
  65. vr++;
  66. pvz = 0;
  67. p--;
  68. }
  69. else
  70. {
  71. int pvr = 0;
  72. vystup_R[pvr++] = text[p];
  73.  
  74. for (int j = pvz -1; j >=0; j--)
  75. vystup_R[pvr++] = vzor[j];
  76. while(vr >= 0)
  77. {
  78. int h = zas[vr-1];
  79. vr --;
  80. for (int j = h -1; j >=0; j--)
  81. vystup_R[pvr++] = vzor[j];
  82. }
  83.  
  84. for (int m = pvr - 1; m >= 0; m--)
  85. vystup[vystup_p++] = vystup_R[m];
  86.  
  87. posl_vypsany = p;
  88. vr = 0;
  89. pvz = 0;
  90. }
  91. }
  92. else
  93. {
  94. for (int v = posl_vypsany+1; v <= p; v++){
  95. vystup[vystup_p++] = text[v];
  96. }
  97. posl_vypsany = p;
  98. // nesouvisi se vzorem
  99. }
  100. }
  101.  
  102.  
  103. p++;
  104.  
  105. }
  106.  
  107. int pvr = 0;
  108.  
  109. for (int j = pvz -1; j >=0; j--)
  110. vystup_R[pvr++] = vzor[j];
  111. while(vr >= 0)
  112. {
  113. int h = zas[vr-1];
  114. vr --;
  115. for (int j = h -1; j >=0; j--)
  116. vystup_R[pvr++] = vzor[j];
  117. }
  118. for (int m = pvr - 1; m >= 0; m--)
  119. vystup[vystup_p++] = vystup_R[m];
  120.  
  121. vystup[vystup_p] = '\0';
  122.  
  123. printf("%s\n",vystup);
  124. }
  125.  
  126.  
  127.  
  128.  
  129. }
  130.  
  131. }

Diff to submission s1175

bugs.cpp

--- c4.s1175.cteam114.bugs.cpp.0.bugs.cpp
+++ c4.s1185.cteam114.bugs.cpp.0.bugs.cpp
@@ -15,5 +15,5 @@
         int n;
 
-        while ( scanf("%i", &n) == 1)
+        while ( scanf("%i ", &n) == 1)
         {
                 gets(vzor);
@@ -121,5 +121,5 @@
                         vystup[vystup_p] = '\0';
 
-                        printf("%s",vystup);
+                        printf("%s\n",vystup);
                 }