-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeautifulString.java
More file actions
47 lines (45 loc) · 1.02 KB
/
BeautifulString.java
File metadata and controls
47 lines (45 loc) · 1.02 KB
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BeautifulString {
public static void main(String[] args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int num;
num = Integer.parseInt(reader.readLine());
String input;
String output;
char previous = 'x';
char current;
char cand;
for (int i = 0; i<num; i++)
{
output = "";
previous = 'x';
input = reader.readLine();
for (int j = 0; j<input.length(); j++)
{
current = input.charAt(j);
if (current == previous)
{
output = "-1";
break;
}
if (current == '?')
{
cand = (char)(97 + (previous-97+1)%3);
if (j < input.length()-1 && input.charAt(j+1) != '?')
{
if (input.charAt(j+1) == cand)
cand = (char)(97 + (cand-97+1)%3);
}
output = output + cand;
}
else
output = output + current;
previous = output.charAt(j);
}
System.out.println(output);
}
}
}