Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("rumbal.in");
  4. ofstream fout("rumbal.out");
  5. int n, m, k;
  6. char ch, depl;
  7. char s[200005];
  8. int x[200005];
  9. int main()
  10. {
  11. fin >> n >> m;
  12. for (int i = 1; i <= n; i++)
  13. {
  14. fin >> ch;
  15. s[i] = ch;
  16. x[i] = 1;
  17. }
  18. for (int i = 1; i <= m; i++)
  19. {
  20. fin >> ch >> depl;
  21. if (depl == 'D')
  22. {
  23. for (int j = 1; j <= n; j++)
  24. {
  25. if (s[j] == ch)
  26. {
  27. if (j == n)
  28. {
  29. k += x[j];
  30. x[j] = 0;
  31. }
  32. else if(x[j])
  33. {
  34. x[j+1] += x[j];
  35. x[j] = 0;
  36. }
  37. }
  38. }
  39. }
  40. else
  41. {
  42. for (int j = 1; j <= n; j++)
  43. {
  44. if (s[j] == ch)
  45. {
  46. if (j == 1)
  47. {
  48. k += x[j];
  49. x[j] = 0;
  50. }
  51. else if (x[j])
  52. {
  53. x[j-1] += x[j];
  54. x[j] = 0;
  55. }
  56. }
  57. }
  58. }
  59. }
  60. fout << n - k;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement