Source code for submission s1212

Go to diff to previous submission

bugs.cpp

  1. #include<iostream>
  2.  
  3. #include<vector>
  4. #include<algorithm>
  5. #include<map>
  6. #include<set>
  7. #include<list>
  8. #include<stack>
  9. #include<queue>
  10.  
  11. #include<stdio.h>
  12. #include<stdlib.h>
  13. #include<math.h>
  14. #include<string.h>
  15.  
  16. using namespace std;
  17.  
  18. #define FOR(i,a,b) for(int i=a;i<=b;i++)
  19.  
  20. #define PB push_back
  21. #define PII pair<int,int>
  22. #define PLL pair<ll,ll>
  23. #define MP make_pair
  24. #define fi first
  25. #define se second
  26.  
  27. #define SIZE(s) (int) (s).size()
  28.  
  29. #define INF 987654321
  30. #define ll long long
  31.  
  32. //----------------------
  33.  
  34. #define MAX 2000047
  35. #define MAX2 1047
  36.  
  37. char p[MAX2];
  38. char text[MAX];
  39. int N,M;
  40.  
  41. bool ok()
  42. {
  43. //cout << "idem ok" << N << " " << M << endl;
  44. //N je velkost daneho
  45. if (N < M-1) return false;
  46.  
  47. if (M > 1 && text[N-(M-1)] != p[0]) return false;
  48.  
  49. if (M>1)
  50. {
  51. int random_id = rand() % (M-1);
  52. //cout << M << " " << random_id << " " << N << " " << (N-(M-2-random_id)) << endl;
  53. if (text[N-(M-1-random_id)] != p[random_id]) return false;
  54. }
  55.  
  56. int j = M-2;
  57. int i = N-1;
  58. while(j >= 0 && text[i] == p[j])
  59. {
  60. j--;
  61. i--;
  62. }
  63. //cout << j << endl;
  64. if (j == -1) return true;
  65. return false;
  66. }
  67.  
  68.  
  69. int main()
  70. {
  71. int q;
  72. char c;
  73. while(scanf("%d %s",&q,p) == 2)
  74. {
  75. M = (int) strlen(p);
  76. getchar();
  77. while(q--)
  78. {
  79. N = 0;
  80. while((c=getchar()) != '\n')
  81. {
  82. //cout << "prislo " << c << endl;
  83. //FOR(i,0,N-1)putchar(text[i]); putchar('\n');
  84. //cout << N << endl;
  85. if (p[M-1] == c && ok())
  86. N -= M-1;
  87. else
  88. text[N++] = c;
  89.  
  90. //FOR(i,0,N-1)putchar(text[i]); putchar('\n');
  91. //cout << endl;
  92. }
  93. text[N] = '\0';
  94.  
  95. FOR(i,0,N-1)putchar(text[i]); putchar('\n');
  96. //printf("%s\n",text);
  97. }
  98. }
  99.  
  100. return 0;
  101. }
  102.  
  103.  

Diff to submission s1169

bugs.cpp

--- c4.s1169.cteam075.bugs.cpp.0.bugs.cpp
+++ c4.s1212.cteam075.bugs.cpp.0.bugs.cpp
@@ -45,4 +45,13 @@
         if (N < M-1) return false;
 
+        if (M > 1 && text[N-(M-1)] != p[0]) return false;
+
+        if (M>1)
+        {
+                int random_id = rand() % (M-1);
+                //cout << M << " " <<  random_id << " " << N << " " << (N-(M-2-random_id)) << endl;
+                if (text[N-(M-1-random_id)] != p[random_id]) return false;
+        }
+
         int j = M-2;
         int i = N-1;