Source code for submission s1139

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

Diff to submission s1134

bugs.cpp

--- c4.s1134.cteam114.bugs.cpp.0.bugs.cpp
+++ c4.s1139.cteam114.bugs.cpp.0.bugs.cpp
@@ -2,5 +2,5 @@
 #include <stdlib.h>
 #include <math.h>
-#include <string>
+#include "string.h"
 
 int zas[3000000];