题解 | #扑克牌大小#

扑克牌大小

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

from re import split
import sys

def is_bomb(xs):
    if len(xs)==4:
        if len(set(xs)) == 1:
            return True
    return False

def compare(c1,c2):
    if c1 =='joker JOKER' or c2 == 'joker JOKER':
        return 'joker JOKER'

    cp1 = c1.split()
    cp2 = c2.split()

    if is_bomb(cp1) and not is_bomb(cp2):
        return c1
    if is_bomb(cp2) and not is_bomb(cp1):
        return c2

    if len(cp1) != len(cp2):
        return 'ERROR'

    dic = {x:index for index, x in enumerate(("3 4 5 6 7 8 9 1 J Q K A 2 j J").split())}

    if dic[c1[0]]> dic[c2[0]]:
        return c1
    else:
        return c2




card_1, card_2 = input().split('-')

print(compare(card_1,card_2))

把特殊条件全部去除后比较第一个单词就行

全部评论

相关推荐

点赞 评论 收藏
分享
头顶尖尖的程序员:我也是面了三四次才放平心态的。准备好自我介绍,不一定要背熟,可以记事本写下来读。全程控制语速,所有问题都先思考几秒,不要急着答,不要打断面试官说话。
点赞 评论 收藏
分享
07-01 13:37
门头沟学院 Java
steelhead:不是你的问题,这是社会的问题。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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