-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoker_Game.py
66 lines (56 loc) · 1.45 KB
/
Poker_Game.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
Author: Pavith Bambaravanage
URL: https://github.com/Pavith19
"""
N, K = input().split()
cards = ["2","3","4","5","6","7","8","9","X","J","Q","K","A"]
commun = {}
mine = {}
impossible = False
total = 0
for i in cards:
commun[i] = -1
mine[i] = 0
deck = input()
moves = input()
for i in range(int(N)):
if moves[i] == "n":
if commun[deck[i]] == 0:
impossible = True
break
else:
commun[deck[i]] = 0
elif commun[deck[i]] == -1:
commun[deck[i]] = 1
mine[deck[i]] = 1
total += 1
elif commun[deck[i]] >= 1:
commun[deck[i]] += 1
if total > int(K) or impossible:
print("impossible")
else:
left = int(K) - total
step = 0
hand = ""
while left:
commun_sort = sorted(commun.items(), reverse=True, key=lambda x: x[1])
if commun_sort[step][1] == 0:
step += 1
elif commun_sort[step][1] > 0 and commun_sort[step][1] + mine[commun_sort[step][0]] < 4:
mine[commun_sort[step][0]] += 1
left -= 1
elif mine[commun_sort[step][0]] < 4:
mine[commun_sort[step][0]] += 1
left -= 1
else:
step += 1
if step > 12:
impossible = True
break
for i in mine:
for j in range(mine[i]):
hand += i
if impossible:
print("impossible")
else:
print(hand)