题解 | 扑克牌大小
扑克牌大小
https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb
#细化判断逻辑: #先判断是否有对王,若有则直接输出对王。 #接着判断炸弹情况,若只有一手牌是炸弹,则输出该手牌;若两手牌都是炸弹,则比较炸弹的牌面大小。 #再判断顺子情况,若两手牌都是顺子,则比较顺子中最小牌的大小。 #最后处理其他相同类型的牌(如对子、三个),比较首张牌的大小。 dic = { '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 isboom(lst): return len(lst) == 4 and len(set(lst)) == 1 def is_straight(lst): if len(lst) != 5: return False values = [dic[card] for card in lst] return sorted(values) == list(range(min(values), min(values) + 5)) while True: try: s1, s2 = input().split('-') lst1, lst2 = s1.split(), s2.split() L1, L2 = len(lst1), len(lst2) # 先判断对王 if 'joker JOKER' in (s1, s2): print('joker JOKER') # 判断炸弹 elif isboom(lst1) and not isboom(lst2): print(s1) elif isboom(lst2) and not isboom(lst1): print(s2) elif isboom(lst1) and isboom(lst2): if dic[lst1[0]] > dic[lst2[0]]: print(s1) else: print(s2) # 判断顺子 elif is_straight(lst1) and is_straight(lst2): if dic[lst1[0]] > dic[lst2[0]]: print(s1) else: print(s2) # 其他相同类型的牌(如对子、三个) elif L1 == L2: if dic[lst1[0]] > dic[lst2[0]]: print(s1) else: print(s2) else: print('ERROR') except: break