-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorrect_path.py
More file actions
68 lines (60 loc) · 1.5 KB
/
Copy pathcorrect_path.py
File metadata and controls
68 lines (60 loc) · 1.5 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def CorrectPath(st):
n_r = 0
n_l = 0
n_u = 0
n_d = 0
n_q = 0
n_r2 = 0
n_l2 = 0
n_u2 = 0
n_d2 = 0
new_word = ""
st = list(st)
for i in st:
if i == "r":
n_r += 1
elif i == "l":
n_l += 1
elif i == "d":
n_d += 1
elif i == "u":
n_u += 1
elif i == "?":
n_q += 1
for i in range(0, len(st)):
if st[i] == "r":
n_r2 += 1
if st[i] == "l":
n_l2 += 1
if st[i] == "d":
n_d2 += 1
if st[i] == "u":
n_u2 += 1
if (st[i] == "?") and ((n_r - n_l) < 4):
st[i] = "r"
n_r += 1
n_q -= 1
elif (st[i] == "?") and ((n_r - n_l) > 4):
st[i] = "l"
n_l += 1
n_q -= 1
elif (st[i] == "?") and ((n_d - n_u) < 4):
st[i] = "d"
n_d += 1
n_q -= 1
elif (st[i] == "?") and ((n_d - n_u) > 4):
st[i] = "u"
n_u += 1
n_q -= 1
elif (st[i] == "?") and ((n_d - n_u) == 4) and ((n_r - n_l) == 4) and ((n_d2 - n_u2) > 1):
st[i] = "u"
n_u += 1
n_q -= 1
elif (st[i] == "?") and ((n_d - n_u) == 4) and ((n_r - n_l) == 4) and ((n_d2 - n_u2) < 1):
st[i] = "d"
n_d += 1
n_q -= 1
st = ''.join(st)
return st
# keep this function call here
print(CorrectPath(input()))