题解 | #扑克牌大小#

扑克牌大小

https://www.nowcoder.com/practice/d290db02bacc4c40965ac31d16b1c3eb

a, b = input().strip().split('-')

poker_map = {
    '2': 15, '3': 3, '4': 4, '5': 5, 
    '6': 6, '7': 7, '8': 8, '9': 9, '10': 10,
    'J': 11, 'Q': 12, 'K': 13, 'A': 14,
    'joker': 15, 'JOKER': 16
}

# type
# 1 -- 1,2,3,5
# 4 -- 4
def get_type(s):
    if len(s) in [1, 3, 5]:
        return 1
    if len(s) == 2:
        return 1 if 'joker' not in s else 4
    return 4

def compare(a, b):
    sa, sb = a.split(' '), b.split(' ')
    if not isinstance(sa, list):
        sa = [sa]
    if not isinstance(sb, list):
        sb = [sb]
    ta, tb = get_type(sa), get_type(sb)
    if ta == 4:
        if tb != 4: return a 
        if 'joker' in a: return a 
        if 'joker' in b: return b 
        return a if poker_map[sa[0]] > poker_map[sb[0]] else b
    
    if ta == 1:
        if tb == 4: return b
        if len(sa) != len(sb): return "ERROR"
        return a if poker_map[sa[0]] > poker_map[sb[0]] else b

print(compare(a, b))

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 12:04
毕业生招你惹你了,问一个发薪日来一句别看网上乱七八糟的你看哪个工作没有固定发薪日扭头就取消了面试就问了一句公司都是这个态度吗还搞上人身攻击了...
程序员小白条:呃呃呃,都还没面试,我都不会问这么细,何况通不通过,去不去都另说,你没实力和学历的话,在外面就这样,说实话没直接已读不回就不错了,浪费时间基本上
点赞 评论 收藏
分享
MinJerous:虽然我一直说 计算机不怎么卡学历 但是至少得一本
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 12:10
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务