Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void solve()
- {
- int n, cnt = 0, j = 0;
- cin >> n;
- string s, holder;
- cin >> s;
- vector<int> blue(s.length() + 1, 0), yellow(s.length() + 1, 0), red(s.length() + 1, 0);
- for (int i = 0; i < s.length(); i++)
- {
- if (s[i] == 'O')
- red[i]++, yellow[i]++;
- else if (s[i] == 'P')
- red[i]++, blue[i]++;
- else if (s[i] == 'G')
- yellow[i]++, blue[i]++;
- else if (s[i] == 'A')
- red[i]++, blue[i]++, yellow[i]++;
- else if (s[i] == 'R')
- red[i]++;
- else if (s[i] == 'Y')
- yellow[i]++;
- else if (s[i] == 'B')
- blue[i]++;
- }
- for (int i = 0; i < s.length(); i++)
- {
- if (blue[i])
- {
- cnt++;
- while (blue[i])
- i++;
- i--;
- }
- }
- for (int i = 0; i < s.length(); i++)
- {
- if (yellow[i])
- {
- cnt++;
- while (yellow[i])
- i++;
- i--;
- }
- }
- for (int i = 0; i < s.length(); i++)
- {
- if (red[i])
- {
- cnt++;
- while (red[i])
- i++;
- i--;
- }
- }
- cout << cnt << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment