-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path1265A.cpp
More file actions
executable file
·49 lines (41 loc) · 799 Bytes
/
Copy path1265A.cpp
File metadata and controls
executable file
·49 lines (41 loc) · 799 Bytes
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
// Problem Code: 1265A
#include <iostream>
#include <string>
#include <unordered_set>
using namespace std;
char update(char l, char r) {
unordered_set<char> set = {'a', 'b', 'c'};
set.erase(l);
set.erase(r);
return *set.begin();
}
string construct(string& s) {
int n = s.length();
// Base Cases
if (n == 1)
return (s[0] == '?') ? "a" : s;
if (s[0] == '?')
s[0] = update('?', s[1]);
if (s[n - 1] == '?')
s[n - 1] = update(s[n - 2], '?');
if (s[0] == s[1])
return "-1";
// Construct beautiful string
for (int i = 1; i < n - 1; i++) {
if (s[i] == '?')
s[i] = update(s[i - 1], s[i + 1]);
else if (s[i] == s[i + 1])
return "-1";
}
return s;
}
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
cout << construct(s) << endl;
}
return 0;
}