折叠

PAT乙级-1018 锤子剪刀布

 

 

 

 解题代码(部分运行超时及错误 12分):

 

N = int(input())
jiaofeng_list = []
for i in range(N):
    jiaofeng_list.append(list(map(str,input().rstrip().split())))

def panding(A,B):
    if A == 'C' and B == 'J':
        return ["shengA","C"]
    elif A == 'J' and B == 'B':
        return ["shengA","J"]
    elif A == 'B' and B == 'C':
        return ["shengA","B"]
    elif A == 'C' and B == 'C':
        return "ping"
    elif A == 'J' and B == 'J':
        return "ping"
    elif A == 'B' and B == 'B':
        return "ping"
    elif B == 'C' and A == 'J':
        return ["shengB","C"]
    elif B == 'J' and A == 'B':
        return ["shengB","J"]
    elif B == 'B' and A == 'C':
        return ["shengB","B"]

sheng_A = 0
ping_A = 0
fu_A = 0
sheng_B = 0
ping_B = 0
fu_B = 0
A_shoushi = []
B_shoushi = []

for i in range(len(jiaofeng_list)):
    if panding(jiaofeng_list[i][0],jiaofeng_list[i][1])[0] == "shengA":
        sheng_A+= 1
        fu_B += 1
        A_shoushi.append(panding(jiaofeng_list[i][0],jiaofeng_list[i][1])[1])
    elif panding(jiaofeng_list[i][0],jiaofeng_list[i][1]) == "ping":
        ping_A += 1
        ping_B += 1
    else:
        fu_A += 1
        sheng_B += 1
        B_shoushi.append(panding(jiaofeng_list[i][0],jiaofeng_list[i][1])[1])

print(sheng_A,end = ' ')
print(ping_A,end = ' ')
print(fu_A)
print(sheng_B,end = ' ')
print(ping_B,end = ' ')
print(fu_B)

def endshoushi(A):
    B=set(A)
    C={}
    for item in B:
        C.update({item:A.count(item)})
    C = list(C.items())
    max_num = -1
    end_str = ''
    for i in range(len(C)):
        if C[i][1] > max_num:
            max_num = C[i][1]
            end_str = C[i][0]
        elif C[i][1] == max_num and C[i][0]<end_str:
            end_str = C[i][0]
    return end_str

print(endshoushi(A_shoushi),end = ' ')
print(endshoushi(B_shoushi),end = '')

 

posted @ 2021-11-23 19:44  Coverpast  阅读(36)  评论(0编辑  收藏  举报