题解 | #扑克牌大小#

扑克牌大小

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

while True:
    try:
        a = input().split('-') #分开为两手牌
        first_poker,second_poker =a[0],a[1]
        type_1 = 0
        type_2 = 0
        first_poker = (first_poker.split()) #按空格将牌分开
        second_poker = (second_poker.split())
        len_1 = len(first_poker)
        len_2 = len(second_poker)
        if(len_1 == 1): #type = 1,2,3,4,5,6分别代表 单牌,对子,三张,炸弹,顺子,对王
            type_1 = 1
        if(len_1 == 2):
            if(first_poker[0] == 'joker'): #两张牌有可能是对子也有可能是对王
                type_1 = 6
            else:
                type_1 = 2
        if(len_1 == 3):
            type_1 = 3
        if(len_1 == 4):
            type_1 = 4
        if(len_1 == 5):
            type_1 = 5
            
        if(len_2 == 1):
            type_2 = 1
        if(len_2 == 2):
            if(second_poker[0] == 'joker'):
                type_2 = 6 
            else:
                type_2 = 2
        if(len_2 == 3):
            type_2 = 3
        if(len_2 == 4):
            type_2 = 4
        if(len_2 == 5):
            type_2 = 5
        S = {'3': 3, '4': 4,'5': 5,'6': 6,'7': 7,'8': 8,'9': 9,'10': 10,'J': 11,'Q': 12,'K': 13,'A': 14,'2': 15,'joker':16,'JOKER':17} #按题目给的表示每张牌的大小顺序赋值
        if(type_1 != type_2): #不是同一类型的
            if(type_1 == 6) | (type_2 == 6):#可能有王炸
                if(type_1 == 6):
                    print('joker JOKER')
                if(type_2 == 6):
                    print('joker JOKER')
            elif(type_1 == 4) | (type_2 == 4): #可能有炸弹
                if(type_1 == 4):
                    print(*first_poker)
                if(type_2 == 4):
                    print(*second_poker)
            else: #不是以上两种情况则认为无法比较
                print('ERROR')
        else: #否则
            if(S[first_poker[0]] > S[second_poker[0]]): #只需要看第一张牌的大小就能比出来整幅牌的大小顺序
                print(*first_poker)
            else:
                print(*second_poker)
    except:
        break
华为机试题解(prod.by kedao) 文章被收录于专栏

华为实习机试题解

全部评论

相关推荐

白火同学:1、简历可以浓缩成一页,简历简历先要“简”方便HR快速过滤出有效信息,再要“历”用有效信息突出个人的含金量。 2、教育背景少了入学时间~毕业时间,HR判断不出你是否为应届生。 3、如果你的平台账号效果还不错,可以把账号超链接或者用户名贴到对应位置,一是方便HR知道你是具体做了什么内容的运营,看到账号一目了然,二是口说无凭,账号为证,这更有说服力。
面试被问期望薪资时该如何...
点赞 评论 收藏
分享
02-28 13:25
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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