Python笔试题: 足球双循环赛制积分计算方法

足球双循环赛制:双循环是所有参加比赛的队均能相遇两次,最后按各队在两个循环的全部比赛中的积分、得失分率排列名次。

说明:一场比赛,赢者积3分,输者积0分,平局各积1分,输出按照每队积分排名降序排列,如果两队积分相同,则按照队名升序排列。

示例1:

输入

a-b 3:0
b-a 1:1

输出

a 4,b 1

示例2:

输入

a-b 3:0
a-c 2:1
b-a 1:1
c-a 0:1
b-c 4:3
c-b 2:2

输出

a 10,b 5,c 1

Python代码:

import sys

data = sys.stdin.readline().strip()
inputlist = []
while True:
    inputlist.append(data)
    data = sys.stdin.readline().strip()
    if data == '':
        break

scores = {}
for i in inputlist:
    splitlist = i.split()
    name1 = splitlist[0][0]
    name2 = splitlist[0][2]
    scores1 = int(splitlist[1][0])
    scores2 = int(splitlist[1][2])
    if name1 not in scores.keys():
        scores[name1] = 0
    if name2 not in scores.keys():
        scores[name2] = 0

    if scores1 > scores2:
        scores[name1] = scores[name1] + 3
    elif scores1 == scores2:
        scores[name1] = scores[name1] + 1
        scores[name2] = scores[name2] + 1
    elif scores1 < scores2:
        scores[name2] = scores[name2] + 3

result = sorted(scores.items(), key=lambda x: (-x[1], x[0]))

for j in result:
    if j != result[-1]:
        print(*j, end=',')
    else:
        print(*j)
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值