-
Notifications
You must be signed in to change notification settings - Fork 0
/
mocha_and_red_blue.py
39 lines (35 loc) · 1.03 KB
/
mocha_and_red_blue.py
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
'''
Problem Link http://codeforces.com/problemset/problem/1559/B
'''
def opposite(e):
if (e == 'R'):
return 'B'
return 'R'
t = int(input())
for _ in range(t):
n = int(input())
word = list(input())
empty_places = 0
for c in word:
if (c == '?'):
empty_places += 1
if (empty_places == n):
prev = 'B'
for i in range(n):
word[i] = prev
prev = opposite(prev)
elif empty_places > 0:
while (empty_places != 0):
for i in range(0, n):
if word[i] == '?':
if (i > 0) :
if (word[i-1] != '?'):
word[i] = opposite(word[i-1])
empty_places -= 1
continue
if (i < n-1):
if (word[i+1] != '?'):
word[i] = opposite(word[i+1])
empty_places -= 1
continue
print(''.join(word))