题解 | #扑克牌大小#
扑克牌大小
https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb
left, right = input().strip().split('-')
left_cards = left.split()
right_cards = right.split()
left_com = {}
right_com = {}
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 compose(cards: list[str]) -> dict:
i = 0
res = {}
while i < len(cards):
cur = cards[i]
boom = cur * 4
triple = cur * 3
double = cur * 2
if (cur == 'joker' or cur == 'JOKER') and len(cards) == 2:
res['joker'] = cur
return res
if boom == ''.join(cards[i:]):
res['boom'] = cur
return res
elif triple == ''.join(cards[i:]):
res['triple'] = cur
return res
elif double == ''.join(cards[i:]):
res['double'] = cur
return res
else:
if len(cards) == 5:
res['sequence'] = cur
else:
res['single'] = cur
return res
left_com, right_com = compose(left_cards), compose(right_cards)
left_key = list(left_com.keys())[0]
right_key = list(right_com.keys())[0]
if 'joker' == left_key:
print(left)
elif 'joker' == right_key:
print(right)
else:
if left_key == right_key:
l_value = card_value[left_com[left_key]]
r_value = card_value[right_com[right_key]]
print(left) if l_value > r_value else print(right)
elif left_key == 'boom':
print(left)
elif right_key == 'boom':
print(right)
else:
print('ERROR')
查看9道真题和解析