-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7a.py
More file actions
73 lines (62 loc) · 1.39 KB
/
7a.py
File metadata and controls
73 lines (62 loc) · 1.39 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
69
70
71
72
73
hands = [x.split(" ") for x in open("7.in","r").read().split("\n")]
types = ["5OAK","4OAK","FH","3OAK","2P","1P","HC"]
cards = "A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, 2".split(", ")
def getType(hand):
h = {}
for ct in cards:
h[ct] = 0
for i in hand:
h[i] += 1
hv = list(h.values())
nhv = []
for i in hv:
if i != 0:
nhv.append(i)
hv = nhv
hv = sorted(hv)
if hv == [5]:
return 0
elif hv == [1,4]:
return 1
elif hv==[2,3]:
return 2
elif hv==[1,1,3]:
return 3
elif hv == [1,2,2]:
return 4
elif hv == [1,1,1,2]:
return 5
elif hv == [1,1,1,1,1]:
return 6
else:
print(hand)
def checkofHandAisGreater(a,b):
handa = a[0]
handb = b[0]
ta = getType(handa)
tb = getType(handb)
if ta<tb:
return True
elif tb<ta:
return False
for i in range(5):
if cards.index(handa[i])<cards.index(handb[i]):
return True
if cards.index(handa[i])>cards.index(handb[i]):
return False
mins = []
s = 0
c = 1
for i in range(len(hands)):
d = hands[0]
pp = 0
while d in mins:
d = hands[pp]
pp+=1
for hand in hands[1:]:
if (not (hand in mins)) and checkofHandAisGreater(d,hand):
d= hand
mins.append(d)
s += c*int(d[1])
c+=1
print(s)