forked from prateekshyap/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MochaAndRedAndBlue.java
49 lines (47 loc) · 1.19 KB
/
MochaAndRedAndBlue.java
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
/*https://codeforces.com/problemset/problem/1559/B*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class MochaAndRedAndBlue
{
public static void main(String[] args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int tests = Integer.parseInt(reader.readLine());
int n, i;
char[] rowChars;
boolean isLetterFound = false;
while (tests-- > 0)
{
n = Integer.parseInt(reader.readLine());
rowChars = reader.readLine().toCharArray();
isLetterFound = false;
for (i = 0; i < n; ++i)
if (rowChars[i] == 'B' || rowChars[i] == 'R')
{
isLetterFound = true;
break;
}
if (!isLetterFound) rowChars[0] = 'B';
for (i = 1; i < n; ++i)
{
if (rowChars[i] == '?')
{
if (rowChars[i-1] == 'R') rowChars[i] = 'B';
else if (rowChars[i-1] == 'B') rowChars[i] = 'R';
}
}
for (i = n-2; i >= 0; --i)
{
if (rowChars[i] == '?')
{
if (rowChars[i+1] == 'R') rowChars[i] = 'B';
else if (rowChars[i+1] == 'B') rowChars[i] = 'R';
}
}
for (i = 0; i < n; ++i)
System.out.print(rowChars[i]);
System.out.println();
}
}
}