IMohammedNasr

Untitled

Apr 19th, 2022
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. void solve()
  2. {
  3. int n, cnt = 0, j = 0;
  4. cin >> n;
  5. string s, holder;
  6. cin >> s;
  7. vector<int> blue(s.length() + 1, 0), yellow(s.length() + 1, 0), red(s.length() + 1, 0);
  8. for (int i = 0; i < s.length(); i++)
  9. {
  10. if (s[i] == 'O')
  11. red[i]++, yellow[i]++;
  12. else if (s[i] == 'P')
  13. red[i]++, blue[i]++;
  14. else if (s[i] == 'G')
  15. yellow[i]++, blue[i]++;
  16. else if (s[i] == 'A')
  17. red[i]++, blue[i]++, yellow[i]++;
  18. else if (s[i] == 'R')
  19. red[i]++;
  20. else if (s[i] == 'Y')
  21. yellow[i]++;
  22. else if (s[i] == 'B')
  23. blue[i]++;
  24. }
  25. for (int i = 0; i < s.length(); i++)
  26. {
  27. if (blue[i])
  28. {
  29. cnt++;
  30. while (blue[i])
  31. i++;
  32. i--;
  33. }
  34. }
  35. for (int i = 0; i < s.length(); i++)
  36. {
  37. if (yellow[i])
  38. {
  39. cnt++;
  40. while (yellow[i])
  41. i++;
  42. i--;
  43. }
  44. }
  45. for (int i = 0; i < s.length(); i++)
  46. {
  47. if (red[i])
  48. {
  49. cnt++;
  50. while (red[i])
  51. i++;
  52. i--;
  53. }
  54. }
  55. cout << cnt << '\n';
  56. }
Advertisement
Add Comment
Please, Sign In to add comment