-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheGrandAdv.py
45 lines (37 loc) · 977 Bytes
/
TheGrandAdv.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
40
41
42
43
44
45
def main():
n=int(input())
res=[]
for i in range(n):
AdStr=input()
con=determineAdventure(AdStr)
res.append(con)
for val in res:
if(val):
print("Yes")
else:
print("No")
def determineAdventure(AdStr):
inventory=dict.fromkeys(['$', '*', '|'], 0)
for i in range(len(AdStr)):
if AdStr[i]=='.':
continue
if AdStr[i] in inventory:
inventory[AdStr[i]]+=1
else:
canContinue=meetPerson(AdStr[i], inventory)
if canContinue==False:
return False
if(sum(inventory.values())>0):
return False
else:
return True
def meetPerson(sym, inventory):
canContinue=True
mapping={'t':'|', 'b':'$', 'j':'*'}
if(inventory[mapping[sym]] >0):
inventory[mapping[sym]]-=1
else:
canContinue=False
return canContinue
if __name__ == "__main__":
main()