-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1559B Mocha and Red and Blue.cpp
65 lines (59 loc) · 1.35 KB
/
1559B Mocha and Red and Blue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
author : MishkatIT
created : Saturday 2022-10-29-20.41.25
problem : 1559 B. Mocha and Red and Blue
*/
#include<iostream>
#include<string>
#include<algorithm>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
fio;
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
string str;
cin >> str;
int q = count(str.begin(), str.end(), '?');
if(q == n)
{
for(int i = 0; q > 0; i++)
{
cout << 'B';
q--;
if(q)
{
cout << 'R';
q--;
}
}
cout << '\n';
continue;
}
for(int i = 0; q > 0; i++ )
{
if(str[i] == 'R' or str[i] == 'B')
{
if((i + 1) < n and str[i+1] == '?' )
{
str[i+1] = (str[i] == 'B' ? 'R' : 'B');
q--;
}
if((i - 1) >= 0 and str[i-1] == '?')
{
str[i-1] = (str[i] == 'B' ? 'R' : 'B');
q--;
}
if(i == n-1 and q > 0)
i = 0;
}
}
cout << str << '\n';
}
return 0;
}