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 = '')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值