-
Notifications
You must be signed in to change notification settings - Fork 1
/
solve.py
44 lines (38 loc) · 1.28 KB
/
solve.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
remove_bracket = lambda n:n[:len(n)-1][1:]
child,candy = (int(input()) for x in "22")
client = [input().split() for x in range(child)]
client = {x[0]:remove_bracket(x[1]).split(",") for x in client}
candy_list = [input().split() for x in range(candy)]
candy_list = {x[0]:int(remove_bracket(x[1])) for x in candy_list}
# My model of input here is like this:
"""
2 #length of child
2 # length of candy
### These line below is the list of child
Alice (Chocolate,Guimauve)
Bob (Pecto,Jok)
### These linebelow is the list of Candy
Chocolate (10)
Pecto (30)
"""
"""
file = open("example_input.txt","r")
child,candy = (int(file.readline()) for x in "22")
client = [file.readline().split() for x in range(child)]
client = {x[0]:remove_bracket(x[1]).split(",") for x in client}
candy_list = [file.readline().split() for x in range(candy) ]
candy_list = {x[0]:int(remove_bracket(x[1])) for x in candy_list}
file.close()
"""
print(client)
print(candy_list )
res = {}
for x in candy_list :
s = candy_list[x]//[e for i in list(client.values()) for e in i].count(x)
selected = [i for i in client if x in client[i]]
for i in selected:
if i not in list(res.keys()):res[i]={}
res[i][x] = s
for x in res:
t = ",".join(i+" ("+str(res[x][i])+")" for i in res[x])
print(x+" : "+t)