-
Notifications
You must be signed in to change notification settings - Fork 2
/
FShort.py
39 lines (33 loc) · 914 Bytes
/
FShort.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
import sys
if len(sys.argv)<=1:
handIndex=2 # default to South
elif sys.argv[1].upper() in ('N', 'NORTH'): # 1st parameter: N/E/S/W
handIndex=0
elif sys.argv[1].upper() in ('E', 'EAST'):
handIndex=1
elif sys.argv[1].upper() in ('S', 'SOUNTH'):
handIndex=2
elif sys.argv[1].upper() in ('W', 'WEST'):
handIndex=3
else:
handIndex=2 # default to South
EoF = False
try:
line = input() # 1st line
except EOFError:
EoF = True
while not EoF:
l = line.strip().split(',') # str ==> list
if len(l)==52:
h = l[handIndex*13 : handIndex*13+13] # get one hand, N/E/S/W
shape = [0, 0, 0, 0]
for card in h:
shape[(int(card)-1)//13] += 1
shape.sort(reverse=True)
if shape[3]<=1:
print(line.strip()) # output hand in correct shape
try:
line = input() # read next line
except EOFError:
EoF = True
exit(0)