Source code for submission s1169

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. int j = M-2;
  48. int i = N-1;
  49. while(j >= 0 && text[i] == p[j])
  50. {
  51. j--;
  52. i--;
  53. }
  54. //cout << j << endl;
  55. if (j == -1) return true;
  56. return false;
  57. }
  58.  
  59.  
  60. int main()
  61. {
  62. int q;
  63. char c;
  64. while(scanf("%d %s",&q,p) == 2)
  65. {
  66. M = (int) strlen(p);
  67. getchar();
  68. while(q--)
  69. {
  70. N = 0;
  71. while((c=getchar()) != '\n')
  72. {
  73. //cout << "prislo " << c << endl;
  74. //FOR(i,0,N-1)putchar(text[i]); putchar('\n');
  75. //cout << N << endl;
  76. if (p[M-1] == c && ok())
  77. N -= M-1;
  78. else
  79. text[N++] = c;
  80.  
  81. //FOR(i,0,N-1)putchar(text[i]); putchar('\n');
  82. //cout << endl;
  83. }
  84. text[N] = '\0';
  85.  
  86. FOR(i,0,N-1)putchar(text[i]); putchar('\n');
  87. //printf("%s\n",text);
  88. }
  89. }
  90.  
  91. return 0;
  92. }
  93.  
  94.