-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1837-C.py
39 lines (31 loc) · 920 Bytes
/
1837-C.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
t = int(input())
for _ in range(t):
s = input().strip()
res = s
streaks = []
streak = 1
for i in range(1, len(s)):
if (s[i] == s[i - 1]):
streak += 1
else:
streaks.append(s[i-1] * streak)
streak = 1
streaks.append(s[-1] * streak)
for i in range(len(streaks)):
streak_str = streaks[i]
n = len(streak_str)
if streak_str[0] == "?":
if (i == 0):
print("0" * n, end="")
elif (i == len(streaks) - 1):
print("1" * n, end="")
else:
prev_char = streaks[i - 1][0]
next_char = streaks[i + 1][0]
if (prev_char != next_char):
print("1" * n, end="")
else:
print(prev_char * n, end="")
else:
print(streak_str, end="")
print("")