题解 | 扑克牌大小
扑克牌大小
https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb
card_value = {
"3": 1,
"4": 2,
"5": 3,
"6": 4,
"7": 5,
"8": 6,
"9": 7,
"10": 8,
"J": 9,
"Q": 10,
"K": 11,
"A": 12,
"2": 13,
"joker": 14,
"JOKER": 15,
}
def is_king(cards):
return len(cards) == 2 and set(cards) == {"joker", "JOKER"}
def is_bomm(cards):
return len(cards) == 4 and len(set(cards)) == 1
while True:
try:
left_str, right_str = input().split("-")
left = left_str.split()
right = right_str.split()
if is_king(left):
print(left_str)
continue
if is_king(right):
print(right_str)
continue
if is_bomm(left) and not is_bomm(right):
print(left_str)
continue
if is_bomm(right) and not is_bomm(left):
print(right_str)
continue
if is_bomm(left) and is_bomm(right):
print(left_str if card_value[left[0]] > card_value[right[0]] else right_str)
continue
if len(right) != len(left):
print("ERROR")
continue
if len(left) in (1, 2, 3, 5):
left_val = card_value[left[0]]
right_val = card_value[right[0]]
else:
print("ERROR")
continue
if left_val > right_val:
print(left_str)
else:
print(right_str)
except:
break
查看17道真题和解析