Advertisement
Promi_38

cf 1559B

Oct 22nd, 2021
1,226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <bits\stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int t;
  8.     cin >> t;
  9.    
  10.     while(t--)
  11.     {
  12.         int n, i;
  13.         cin >> n;
  14.        
  15.         string s;
  16.         cin >> s;
  17.        
  18.         int cnt = 0;
  19.         for(i = 0; i < n; i++)
  20.         {
  21.             if(s[i] == '?') cnt++;
  22.         }
  23.        
  24.         if(cnt == n)
  25.         {
  26.             for(i = 0; i < n / 2; i++) printf("BR");
  27.             if(n % 2 != 0) printf("B");
  28.             printf("\n");
  29.         }
  30.        
  31.         else
  32.         {
  33.             for(i = 0; i < n; i++)
  34.             {
  35.                 if(s[i] == '?')
  36.                 {
  37.                     if(i > 0)
  38.                     {
  39.                         if(s[i-1] == 'R') s[i] = 'B';
  40.                         else if(s[i-1] == 'B') s[i] = 'R';
  41.                     }
  42.                     if(i < n)
  43.                     {
  44.                         if(s[i+1] == 'R') s[i] = 'B';
  45.                         else if(s[i+1] == 'B') s[i] = 'R';
  46.                     }
  47.                 }
  48.             }
  49.            
  50.             for(i = n; i >= 0; i--)
  51.             {
  52.                 if(s[i] == '?')
  53.                 {
  54.                     if(i > 0)
  55.                     {
  56.                         if(s[i-1] == 'R') s[i] = 'B';
  57.                         else if(s[i-1] == 'B') s[i] = 'R';
  58.                     }
  59.                     if(i < n)
  60.                     {
  61.                         if(s[i+1] == 'R') s[i] = 'B';
  62.                         else if(s[i+1] == 'B') s[i] = 'R';
  63.                     }
  64.                 }
  65.             }
  66.             cout << s << endl;
  67.         }
  68.     }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement