题解 | #扑克牌大小#
扑克牌大小
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) 文章被收录于专栏
华为实习机试题解