Mehulcoder

Accenture

Oct 24th, 2020 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. /*
  2. Author: Mehul Chaturvedi
  3. */
  4.  
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7.  
  8. /*
  9.     Just keep a check that whether the current sequence is of wwbbb type or bbbwwww type
  10.     or both. Rest is pretty trivial.
  11. */
  12. void solve() {
  13.     string s; cin >> s;
  14.     bool bw = 1, wb = 0;
  15.     int b = 1, w = 1;
  16.     int i = 0;
  17.     for (auto &elem : s) {
  18.         i++;
  19.         char c = ((i % 2 == 0) ? 'W' : 'B');
  20.         if (elem == 'R') {
  21.             if (c == 'W') {
  22.                 if (bw == 1) {
  23.                     w++;
  24.                     wb = 0;
  25.                 } else {
  26.                     b = 0;
  27.                     w = i + 2;
  28.                     bw = 1;
  29.                     wb = 1;
  30.                 }
  31.             } else {
  32.                 if (wb == 1) {
  33.                     bw = 0;
  34.                     b++;
  35.                 } else {
  36.                     w = 0;
  37.                     b = i + 2;
  38.                     wb = 1;
  39.                     bw = 1;
  40.                 }
  41.             }
  42.         } else {
  43.             if (c == 'W') {
  44.                 if (wb == 1) {
  45.                     w++;
  46.                     bw = 0;
  47.                 } else {
  48.                     b = 0;
  49.                     w = i + 2;
  50.                     wb = 1;
  51.                     bw = 1;
  52.                 }
  53.             } else {
  54.                 if (bw == 1) {
  55.                     b++;
  56.                     wb = 0;
  57.                 } else {
  58.                     b = i + 2;
  59.                     w = 0;
  60.                     bw = 1;
  61.                     wb = 1;
  62.                 }
  63.             }
  64.         }
  65.     }
  66.  
  67.     cout << b << " " << w << '\n';
  68.  
  69.     return;
  70. }
  71.  
  72. int main(int argc , char ** argv) {
  73.     ios_base::sync_with_stdio(false) ;
  74.     cin.tie(NULL) ;
  75.  
  76.     int t = 1;
  77.     while (t--) {
  78.         solve();
  79.     }
  80.  
  81.     return 0 ;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment