首页 > 试题广场 >

扑克牌大小

[编程题]扑克牌大小
  • 热度指数:49119 时间限制:C/C++ 10秒,其他语言20秒 空间限制:C/C++ 128M,其他语言256M
  • 算法知识视频讲解
扑克牌游戏大家应该都比较熟悉了,一副牌由54张组成,含3~A,2各4张,小王1张,大王1张。牌面从小到大用如下字符和字符串表示(其中,小写joker表示小王,大写JOKER表示大王):)
3 4 5 6 7 8 9 10 J Q K A 2 joker JOKER
输入两手牌,两手牌之间用“-”连接,每手牌的每张牌以空格分隔,“-”两边没有空格,如:4 4 4 4-joker JOKER
请比较两手牌大小,输出较大的牌,如果不存在比较关系则输出ERROR

基本规则:
(1)输入每手牌可能是个子,对子,顺子(连续5张),三个,炸弹(四个)和对王中的一种,不存在其他情况,由输入保证两手牌都是合法的,顺子已经从小到大排列;
(2)除了炸弹和对王可以和所有牌比较之外,其他类型的牌只能跟相同类型的存在比较关系(如,对子跟对子比较,三个跟三个比较),不考虑拆牌情况(如:将对子拆分成个子)
(3)大小规则跟大家平时了解的常见规则相同,个子,对子,三个比较牌面大小;顺子比较最小牌大小;炸弹大于前面所有的牌,炸弹之间比较牌面大小;对王是最大的牌;
(4)输入的两手牌不会出现相等的情况。

答案提示:
(1)除了炸弹和对王之外,其他必须同类型比较。
(2)输入已经保证合法性,不用检查输入是否是合法的牌。
(3)输入的顺子已经经过从小到大排序,因此不用再排序了.

数据范围:保证输入合法

输入描述:
输入两手牌,两手牌之间用“-”连接,每手牌的每张牌以空格分隔,“-”两边没有空格,如4 4 4 4-joker JOKER。


输出描述:
输出两手牌中较大的那手,不含连接符,扑克牌顺序不变,仍以空格隔开;如果不存在比较关系则输出ERROR。
示例1

输入

4 4 4 4-joker JOKER

输出

joker JOKER
#########
def comp(Two_hands, Left_hand, Right_hand):
    # Left_hand = Two_hands[0].split()
    # Right_hand = Two_hands[1].split()
    if int(Left_hand[0]) > int(Right_hand[0]):
        return Two_hands[0]
    else:
        return Two_hands[1]


while True:
    try:
        inp = input()
        # 两边的牌
        two_hands = inp.split('-')
        left_hand = two_hands[0].split()
        right_hand = two_hands[1].split()

        # replace special ones with numbers for comparison
        ori = ['J', 'Q', 'K', 'A', '2', 'joker', 'JOKER']
        new = ['11', '12', '13', '14', '15', '16', '17']

        for i in range(len(left_hand)):
            for j in range(len(ori)):
                if left_hand[i] == ori[j]:
                    left_hand[i] = new[j]

        for i in range(len(right_hand)):
            for j in range(len(ori)):
                if right_hand[i] == ori[j]:
                    right_hand[i] = new[j]

        if two_hands[0] == 'joker JOKER' or two_hands[1] == 'joker JOKER':
            print('joker JOKER')

        elif len(left_hand) == 4 and len(right_hand) != 4:
            print(two_hands[0])

        elif len(right_hand) == 4 and len(left_hand) != 4:
            print(two_hands[1])

        elif len(left_hand) == 5 and len(right_hand) == 5:
            ori2 = ['14', '15']
            new2 = ['1', '2']  # ['A', '2']

            for i in range(len(left_hand)):
                for j in range(len(ori2)):
                    if left_hand[i] == ori2[j]:
                        left_hand[i] = new2[j]

            for i in range(len(right_hand)):
                for j in range(len(ori2)):
                    if right_hand[i] == ori2[j]:
                        right_hand[i] = new2[j]

            bigger = comp(two_hands, left_hand, right_hand)
            print(bigger)

        elif len(left_hand) == len(right_hand):
            bigger = comp(two_hands, left_hand, right_hand)
            print(bigger)

        else:
            print("ERROR")

    except:
        break
发表于 2022-08-02 11:58:51 回复(0)
list1=['3','4','5','6','7','8','9','10','J','Q','K','A','2','joker','JOKER']
a=input().split('-')
h1,h2=a[0].split(),a[1].split()
n1=len(h1)
n2=len(h2)
if ['joker','JOKER'] in [h1,h2]:
    print('joker JOKER')
elif n1==n2:
    if list1.index(h1[0])>list1.index(h2[0]):
        print(' '.join(h1))
    else:
        print(' '.join(h2))
elif n1 in [1,2,3,5] and n2==4:
    print(' '.join(h2))
elif n2 in [1,2,3,5] and n1==4:
    print(' '.join(h1))
else:
    print('ERROR')

发表于 2021-09-27 13:22:21 回复(0)
cards = input().split("-")
def compare(cards):
    rank = ['3','4','5','6','7','8','9','10',
            'J','Q','K','A','2','joker','JOKER']
    one = cards[0].split()
    other = cards[1].split()
    if cards[0] == "joker JOKER" or cards[0] == "JOKER joker":
        print(cards[0])
        return
    elif cards[1] == "joker JOKER" or cards[1] == "JOKER joker":
        print(cards[1])
        return
    if one.count(one[0]) == len(one) == 4:
        if other.count(other[0]) == len(other) == 4:
            if rank.index(one[0])>rank.index(other[1]):
                print(cards[0])
                return
            else:
                print(cards[1])
                return
        else:
            print(cards[0])
            return
    elif other.count(other[0]) == len(other) == 4:
        print(cards[1])
        return
    if len(one) != len(other):
        print("ERROR")
    else:
        if rank.index(one[0])>rank.index(other[0]):
            print(cards[0])
            return
        else:
            print(cards[1])
            return
compare(cards)

编辑于 2021-09-21 11:56:54 回复(0)
d = {'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}#生成字典,以方便卡牌比较大小
card1,card2 = input().split('-')#将输入的两个手牌保存成两个字符串
#主要分成三种情况:1.有大小王的情况,直接输出大小王 2.没出现大小王时,且两方卡牌数目不相等,要么一方有炸,输出该**,要么无法比较,输出ERROR 3..没出现大小王时,且两方卡牌数目相等,只要比较首张卡牌的大小即可。
#要注意提取的双方卡牌时,10的处理情况,因为10是占有两个字符,所以可以通过card.split()去掉空格符,并直接将每张牌保存成一个字符。
if card1 == 'joker JOKER' or card2 == 'joker JOKER':
    print('joker JOKER')
elif len(card1.split()) != len(card2.split()):
    if len(card1.split()) == 4:
        print(card1)
    elif len(card2.split()) == 4:
        print(card2)
    else:
        print('ERROR')
else:
    if d[card1.split()[0]]>d[card2.split()[0]]:
        print(card1)
    else:
        print(card2)

发表于 2021-08-14 16:57:35 回复(0)
import sys
if __name__ == "__main__":
    str_index = "345678910JQKA2jokerJOKER"
    while True:
        line = sys.stdin.readline().strip()
        if line=="":
            break
        if line.find("joker JOKER")!=-1:
            print("joker JOKER")
            continue
        hand_left = line.split("-")[0]
        hand_right = line.split("-")[1]
        len_left = len(hand_left.split(" "))
        len_right = len(hand_right.split(" "))
        if len_left == len_right:
            max_str = hand_left if str_index.find(hand_left[0])>str_index.find(hand_right[0]) else hand_right
            print(max_str)
        elif len_left != len_right and len_left == 4:
            print(hand_left)
        elif len_left != len_right and len_right == 4:
            print(hand_right)
        else:
            print("ERROR")

发表于 2021-06-24 10:19:21 回复(1)

line_in = input().split('-')
left_in = line_in[0]
right_in = line_in[1]

left = left_in.split(' ')
N_left = len(left)
right = right_in.split(' ')
N_right = len(right)

rule_list = ['3','4','5','6','7','8','9','10','J','Q','K','A','2','joker','JOKER']

if left_in == 'joker JOKER'&nbs***bsp;right_in == 'joker JOKER':
    print('joker JOKER')
elif N_left == 4 and N_right != 4:
    print(left_in)
elif N_left != 4 and N_right == 4:
    print(right_in)
elif N_left != N_right:
    print('ERROR')
else:
    index_left = rule_list.index(left[0])
    index_right = rule_list.index(right[0])
    if index_left > index_right:
        print(left_in)
    else:
        print(right_in)

编辑于 2021-03-13 01:21:49 回复(0)
Python解法:
import sys
 
rank=dict()
for i in range(3,11):
    rank[f"{i}"] = i
rank['J'] = 11
rank['Q'] = 12
rank['K'] = 13
rank['A'] = 14
rank['2'] = 15
rank['joker'] = 16
rank['JOKER'] = 17
 
for line in sys.stdin:
    first = line.split('-')[0]
    second = line.split('-')[1]
    first_cards = first.split()
    second_cards = second.split()
    if len(first_cards)==len(second_cards):
        if rank[first_cards[0]]>rank[second_cards[0]]:
            print(first)
        else:
            print(second)
    elif 'joker' in first_cards+second_cards:
        if 'joker' in first_cards:
            print(first)
        else:
            print(second)
    elif len(first_cards)==4&nbs***bsp;len(second_cards)==4:
        if len(first_cards)==4:
            print(first)
        else:
            print(second)
    else:
        print('ERROR')


发表于 2020-07-14 21:52:48 回复(2)
# -*- coding: utf-8 -*- # @Time    : 2020/7/6 11:48 # @Author  : Shajiu # @FileName: 3_Poker_game.py # @Software: PyCharm # @Github https://github.com/Shajiu ''' 题目: 扑克牌游戏大家应该都比较熟悉了,一副牌由54张组成,含3~A24张,小王1张,大王1张。牌面从小到大用如下字符和字符串表示(其中,小写joker表示小王,大写JOKER表示大王):) 3 4 5 6 7 8 9 10 J Q K A 2 joker JOKER 输入两手牌,两手牌之间用“-”连接,每手牌的每张牌以空格分隔,“-”两边没有空格,如:4 4 4 4-joker JOKER 请比较两手牌大小,输出较大的牌,如果不存在比较关系则输出ERROR 基本规则: 1)输入每手牌可能是个子,对子,顺子(连续5张),三个,**(四个)和对王中的一种,不存在其他情况,由输入保证两手牌都是合法的,顺子已经从小到大排列; 2)除了**和对王可以和所有牌比较之外,其他类型的牌只能跟相同类型的存在比较关系(如,对子跟对子比较,三个跟三个比较),不考虑拆牌情况(如:将对子拆分成个子) 3)大小规则跟大家平时了解的常见规则相同,个子,对子,三个比较牌面大小;顺子比较最小牌大小;**大于前面所有的牌,**之间比较牌面大小;对王是最大的牌; 4)输入的两手牌不会出现相等的情况。 答案提示: 1)除了**和对王之外,其他必须同类型比较。 2)输入已经保证合法性,不用检查输入是否是合法的牌。 3)输入的顺子已经经过从小到大排序,因此不用再排序了. ''' import random class Solution: def poker_game(self):
        poker=["3","4","5","6","7","8","9","10","J","Q","K","A","2","joker","JOKER"] while True:
            A = str(input()).split()
            B = str(input()).split() tmp=None  a_l=len(A)
            b_l=len(B) if set(A)<=set(poker) and set(B)<=set(poker):
                A_id = [poker.index(i) for i in A] #获取对应的索引  B_id = [poker.index(i) for i in B] #获取对应的索引  A_id.sort()
                B_id.sort()
                A = ' '.join(A)
                B = ' '.join(B) tmp = A + "-" + B #王对最大  if poker[A_id[0]]==poker[-2] and poker[A_id[1]]==poker[-1] and poker[B_id[0]]!=poker[-2] and poker[B_id[1]]!=poker[-1]: print(poker[-2],poker[-1]) elif poker[B_id[0]]==poker[-2] and poker[B_id[1]]==poker[-1] and poker[A_id[0]]!=poker[-2] and poker[A_id[1]]!=poker[-1]: print(poker[-2],poker[-1]) elif poker[A_id[0]]==poker[-2] and poker[A_id[1]]==poker[-1] and poker[B_id[0]]==poker[-2] and poker[B_id[1]]==poker[-1]: print('ERROR') #**比其他大  elif a_l==4 and b_l!=4: if A_id[0]==A_id[1]==A_id[2]==A_id[3]: print(poker[A_id[0]],poker[A_id[1]],poker[A_id[2]],poker[A_id[3]]) # **比其他大  elif a_l != 4 and b_l == 4: if B_id[0] == B_id[1] == B_id[2] == B_id[3]: print(poker[B_id[0]], poker[B_id[1]], poker[B_id[2]], poker[B_id[3]]) #个子  elif a_l==b_l==1:
                    id=max(A_id,B_id) print(poker[id[0]]) # 对子  elif a_l==b_l==2 and A_id[0]==A_id[1] and B_id[0]==B_id[1]:
                    id = max(A_id, B_id) print(poker[id[0]],poker[id[1]]) #三个  elif a_l==b_l==3: if A_id[0]< B_id[0] and A_id[1]< B_id[1] and A_id[2]< B_id[2]: print(poker[B_id[0]], poker[B_id[1]], poker[B_id[2]]) elif A_id[0]>B_id[0] and A_id[1]> B_id[1] and A_id[2]>B_id[2]: print(poker[A_id[0]],poker[A_id[1]],poker[A_id[2]]) else: print("ERROR") #**  elif a_l==b_l==4: if A_id[0]==A_id[1]==A_id[2]==A_id[3] and B_id[0]==B_id[1]==B_id[2]==B_id[3]:
                        id=max(A_id,B_id) print(poker[id[0]],poker[id[1]],poker[id[2]],poker[id[3]]) elif A_id[0]==A_id[1]==A_id[2]==A_id[3]: print(poker[A_id[0]],poker[A_id[1]],poker[A_id[2]],poker[A_id[3]]) elif B_id[0] == B_id[1] == B_id[2] == B_id[3]: print(poker[B_id[0]], poker[B_id[1]], poker[B_id[2]], poker[B_id[3]]) #顺子  elif a_l==b_l==5:
                    id=[max(A_id,B_id) for i in range(len(A_id)-1) if A_id[i]+1==A_id[i+1] and B_id[i]+1==B_id[i+1]] print(' '.join([poker[i] for i in id[0]])) elif 'q' in A or 'q' in B: print('结束啦') break   else: print('ERROR') continue   #print(tmp)     #  # '''个子'''  # if num==1:  #     A=poker[random.randint(1,14)]  #     B= poker[random.randint(1, 14)]  #     print(A,"=====",B)  #     Index=max(poker.index(A),poker.index(B))  #     print(poker[Index])  #  # #对子  # elif num==2:  #     A = poker[random.randint(1, 14)]  #     B = poker[random.randint(1, 14)]  #  #  # else:  #     print(num)  if __name__ == '__main__':
    result=Solution()
    result.poker_game()
编辑于 2020-07-06 18:04:08 回复(0)
import sys
while True:
    tp = sys.stdin.readline().strip()
    if not tp:
        break
    if 'joker JOKER' in tp:
        print('joker JOKER')
    else:
        A = ['3','4','5','6','7','8','9','10','J','Q','K','A','2','joker','JOKER']
        N,M = tp.split('-')
        ls1 = N.split()
        ls2 = M.split()
        if len(ls1)==len(ls2):
            print(N if A.index(ls1[0])>A.index(ls2[0]) else M)
        elif len(ls1) == 4 and len(ls2)!=4:
            print(N)
        elif len(ls2) == 4 and len(ls1)!=4:
            print(M)
        else:
            print('ERROR')

发表于 2020-04-04 17:34:59 回复(1)
蠢办法
size_di = {"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}

poker = input()
poker1,poker2 = poker.split("-")
poker1 = poker1.split()
poker2 = poker2.split()
if "joker JOKER" in poker:
    print ("joker JOKER")
elif len(poker1) == 4&nbs***bsp;len(poker2) == 4:
    if len(set(poker1)) == 1 and len(set(poker2)) == 1:
        if size_di[poker1[0]] > size_di[poker2[0]]:
            print (" ".join(poker1))
        else:
            print (" ".join(poker2))
    elif len(set(poker1)) == 1:
        print (" ".join(poker1))
    else:
        print (" ".join(poker2))

elif len(poker1) == len(poker2):
    to1 = 0
    to2 = 0
    for key in poker1:
        to1 += size_di[key]

    for key in poker2:
        to2 += size_di[key]

    if to1 > to2:
        print (" ".join(poker1))
    else:
        print (" ".join(poker2))
else:
    print ('ERROR')


编辑于 2020-02-22 20:07:38 回复(0)
def Tonum(s):
    """
    :type s:str
    :rtype:num
    """
    if s=='J':
        return 11
    elif s=='Q':
        return 12    
    elif s=='K':
        return 13
    elif s=='A':
        return 14
    else:
        return int(s)
    
if __name__== '__main__':
    # 输入
    s = input()
    index=0
    n=len(s)
    for i in range(n):
        if s[i]=='-':
            index=i
    s1=s[0:index].split(" ")
    s2=s[index+1:].split(" ")
    n1=len(s1)
    n2=len(s2)
    s11=s1[0]
    s22=s2[0]
    
    # 有王炸
    if len(s11)>2:
        print(' '.join(s1))
    elif len(s22)>2:
        print(' '.join(s2))
        
    # 有一方四诈 或者输入不对
    elif n1!=n2:
        # 有4个的炸    
        if n1 == 4:
            print(' '.join(s1))
        elif n2 == 4:
            print(' '.join(s2))
        # 输入不对,无法比较
        else:
            print('ERROR')
            
    # 牌数相等比较
    else:
        
        if Tonum(s11)>Tonum(s22):
            print(' '.join(s1))
        else:
            print(' '.join(s2))
发表于 2019-09-11 10:46:14 回复(0)
import sys
while True:
    try:
        a = sys.stdin.readline().strip()
        b = a.replace('2','15').replace('joker','16').replace('JOKER','17').replace('J','11').replace('Q','12').replace('K','13').replace('A','14').split('-')
        l = list(map(int, b[0].split(' ')))
        r = list(map(int,b[1].split(' ')))
        ll = len(l)
        lr = len(r)
        list(map(int, sys.stdin.readline().strip().split()))
        if (l == [17,16] or l == [16,17]):
            re = 0
        elif (r == [17,16] or r == [16,17]):
            re = 1
        elif ll == 4 and lr == 4:
            re = int(l[0]<r[0])
        elif ll == 4 or lr == 4:
            re = 0 if ll == 4 else 1
        elif ll != lr:
            print("ERROR")
            break
        elif ll==1:
            re = int(l<r)
        elif ll == 2:
            re = int(l[0]<r[0])
        elif ll == 3:
            re = int(l[0]<r[0])
        elif ll == 5:
            re = int(l[0]<r[0])
        print(a.split('-')[re])
    except:
        break

发表于 2019-03-17 20:57:35 回复(0)
# 用列表记录大小顺序,不过换成字典效率会更高
string = ['3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A', '2', 'joker', 'JOKER']
while True:
    try:
        a_b = input()
        if 'joker JOKER' in a_b:  # 存在对王时直接输出
            print('joker JOKER')
            continue
        a, b = a_b.split('-')
        if len(a) == 7 or len(b) == 7:  # 如果只有一方存在四张牌,直接输出,否则比较牌面大小
            if len(b) != 7:
                print(a)
            if len(a) != 7:
                print(b)
            if len(a) == 7 and len(b) == 7:
                print(a) if string.index(a.split()[0]) > string.index(b.split()[0]) else print(b)
            continue
        a_arr, b_arr = a.split(), b.split()
        if len(a_arr) != len(b_arr):  # 除去对王和**,牌数不一样大的都报错
            print('ERROR')
            continue
        print(a) if string.index(a.split()[0]) > string.index(b.split()[0]) else print(b)  # 牌数相同比较牌面大小
    except:
        break
发表于 2018-08-10 21:50:14 回复(0)
r,l=list(input().split('-'))
r2=list(r.split())
l2=list(l.split())
rl,ll=len(r2),len(l2)
sort=['3','4','5','6','7','8','9','10','J','Q','K','A','2','joker','JOKER']
if rl==ll:#长度相同时,比较首张牌的大小,输出较大的手牌
    if sort.index(r2[0])>sort.index(l2[0]):
        print(r)
    else:
        print(l)
else:#长度不等时,先检查是否有对王,再检查是否有**,有则输出该手牌,都没有则输出ERROR
    if r=='joker JOKER':
        print(r)
    elif l=='joker JOKER':
        print(l)
    elif rl==4:
        print(r)
    elif ll==4:
        print(l)
    else:
        print('ERROR')

发表于 2018-07-19 21:16:09 回复(0)
 
编辑于 2018-05-22 21:23:12 回复(1)
# 其实单纯解题的话,写的有点多余= =
poker_dict = {
    'dange': 1,
    'duizi': 2,
    'sange': 3,
    'zhadan': 4,
    'shunzi': 5
}

poker_compare_dict = {
    '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 judge(poker):
    if ' ' not in poker:
        return 'dange'
    else:
        poker_list = poker.split(' ')
        if len(poker_list) == 2 and poker_list[0] != 'joker':
            return 'duizi'
        elif len(poker_list) == 3:
            return 'sange'
        elif len(poker_list) == 4 or (len(poker_list) == 2 and poker_list[0] == 'joker'):
            return 'zhadan'
        elif len(poker_list) == 5:
            return 'shunzi'
        else:
            exit(0)


def compare_dange(left_poker, right_poker):
    if poker_compare_dict[left_poker] > poker_compare_dict[right_poker]:
        return left_poker
    return right_poker


def compare_duizi(left_poker, right_poker):
    if poker_compare_dict[left_poker.split(' ')[0]] > poker_compare_dict[right_poker.split(' ')[0]]:
        return left_poker
    return right_poker


def compare_sange(left_poker, right_poker):
    if poker_compare_dict[left_poker.split(' ')[0]] > poker_compare_dict[right_poker.split(' ')[0]]:
        return left_poker
    return right_poker


def compare_zhadan(left_poker, right_poker):
    left_poker_split = left_poker.split(' ')
    right_poker_split = right_poker.split(' ')
    if len(left_poker_split) == 2:
        return left_poker
    elif len(right_poker_split) == 2:
        return right_poker
    elif poker_compare_dict[left_poker_split[0]] > poker_compare_dict[right_poker_split[0]]:
        return left_poker
    else:
        return right_poker
        

def compare_shunzi(left_poker, right_poker):
    if poker_compare_dict[left_poker.split(' ')[0]] > poker_compare_dict[right_poker.split(' ')[0]]:
        return left_poker
    return right_poker


def compare(left_poker, right_poker):
    left_poker_judge = poker_dict[judge(left_poker)]
    right_poker_judge = poker_dict[judge(right_poker)]
    
    if left_poker_judge == 4 and right_poker_judge != 4:
        return left_poker
    elif left_poker_judge != 4 and right_poker_judge == 4:
        return right_poker
    elif left_poker_judge == 1 and right_poker_judge == 1:
        return compare_dange(left_poker, right_poker)
    elif left_poker_judge == 2 and right_poker_judge == 2:
        return compare_duizi(left_poker, right_poker)
    elif left_poker_judge == 3 and right_poker_judge == 3:
        return compare_sange(left_poker, right_poker)
    elif left_poker_judge == 4 and right_poker_judge == 4:
        return compare_zhadan(left_poker, right_poker)
    elif left_poker_judge == 5 and right_poker_judge == 5:
        return compare_shunzi(left_poker, right_poker)
    else:
        return 'ERROR'


if __name__ == '__main__':
    compare_pokers = raw_input().split('-')
    print(compare(compare_pokers[0], compare_pokers[1]))

发表于 2017-03-17 11:41:21 回复(0)
str = raw_input()   #输入字符串
l=str.split('-')         #将字符串按'-'分割成含两个字符串的列表
l1=l[0].split()         #取出第一手牌,存入列表l1
l2=l[1].split()         #取出第二手牌,存入列表l2
len1=len(l1)         #获得第一手牌的长度len1
len2=len(l2)         #获得第二手牌的长度len2
flag=0                  #标志位,用来判断后面长度相等时输出第一手牌还是第二手牌
if l1[0] == 'joker' or l2[0] == 'joker' :      #考虑第一种特殊情况,有双王
    print "joker JOKER"
elif len1 == 4 and len2!=4 or len1!=4 and len2 == 4 :     #考虑第二种特殊情况,有且仅有一个**
    if len1 == 4 :
        print l[0]
    else :
        print l[1]
elif len1 == len2 :                                                         #考虑第三种情况,牌型一样但无双王
    if l1[0]=='A' or l2[0]=='A' :                                           # 特殊情况A>K,实际字符‘A’<'K'
        if l2[0]=='A':
            flag=1
    elif l1[0]=='10' or l2[0]=='10':                                     #特殊情况10>3,实际字符'10'<'3'
        if l1[0]=='10':
            if l2[0].isupper():
                flag=1
        else :
            if not l1[0].isupper():
                flag=1
    elif l1[0]<l2[0]:                                                           #剩下的全部符合实际字符比较大小
        flag=1
    if flag :
        print l[1]
    else:
        print l[0]
else:                                                                        #最后一种情况,无**无双王且牌型不同
    print "ERROR"

发表于 2017-03-10 22:05:42 回复(0)
#可能还有不少问题 但是毕竟是自己写了好久的代码 留个纪念
import sys
ind = "345678910JQKA2"
for line in sys.stdin:
    temp = line.strip().split("-")
    if "joker JOKER" in temp:
        print "joker JOKER"
        continue
    elif len(temp[0].split()) == 4 and len(temp[1].split())!=4:
        print temp[0]
        continue
    elif len(temp[0].split()) != 4 and len(temp[1].split())==4:
        print temp[1]
        continue
    elif len(temp[0].split()) == len(temp[1].split()):
        if ind.index(temp[0].split()[0])> ind.index(temp[1].split()[0]):
            print temp[0]
            continue
        else:
            print temp[1]
            continue
    else:
        print "ERROR"
        continue


发表于 2016-09-20 21:06:19 回复(0)