-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCAKEDOOM.cpp
More file actions
executable file
·48 lines (45 loc) · 808 Bytes
/
Copy pathCAKEDOOM.cpp
File metadata and controls
executable file
·48 lines (45 loc) · 808 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
#include <iostream>
#include <string>
using namespace std;
int main() {
int T;
cin >> T;
for (int t = 0; t < T; ++t) {
int k;
string s;
cin >> k >> s;
int n = s.length();
string ans = "NO";
for (char c = '0'; c < '0' + k; ++c) {
string w = s;
if (w[0] != '?' && w[0] != c) {
continue;
}
bool good = true;
w[0] = c;
for (int i = 1; i < n; ++i) {
bool ok = false;
for (char d = '0'; d < '0' + k; ++ d) {
if (w[i] != '?' && w[i] != d) {
continue;
}
if (d != w[i - 1] && d != w[(i + 1) % n]) {
w[i] = d;
ok = true;
break;
}
}
if (!ok) {
good = false;
break;
}
}
if (good) {
ans = w;
break;
}
}
cout << ans << endl;
}
return 0;
}