python抢红包列表对数据操作的练习题

在这里插入图片描述

输入样例

10
3 2 22 10 58 8 125
5 1 345 3 211 5 233 7 13 8 101
1 7 8800
2 1 1000 2 1000
2 4 250 10 320
6 5 11 9 22 8 33 7 44 10 55 4 2
1 3 8800
2 1 23 2 123
1 8 250
4 2 121 4 516 7 112 9 10

输出样例

1 11.63
2 3.63
8 3.63
3 2.11
7 1.69
6 -1.67
9 -2.18
10 -3.26
5 -3.26
4 -12.32

#[
#    [3, 2, 22, 10, 58, 8, 125],
#    [5, 1, 345, 3, 211, 5, 233, 7, 13, 8, 101],
#    [1, 7, 8800],
#    [2, 1, 1000, 2, 1000],
#    [2, 4, 250, 10, 320],
#    [6, 5, 11, 9, 22, 8, 33, 7, 44, 10, 55, 4, 2],
#    [1, 3, 8800],
#    [2, 1, 23, 2, 123],
#    [1, 8, 250]
#]

amountOfPeople = int(input())
data = []
#对每个数据使用map进行操作
for i in range(amountOfPeople):
    data.append(list(map(int,input().split())))


#生成一个二维列表
#存放结果的列表 【编号,个数,金额】
#[1, 0, 0]
#[2, 0, 0]
#[3, 0, 0]
#[4, 0, 0]
#[5, 0, 0]
#[6, 0, 0]
#[7, 0, 0]
#[8, 0, 0]
#[9, 0, 0]
#[10, 0, 0]
output = [[0 for row in range(3)] for column in range(amountOfPeople)]
for i in range(amountOfPeople):
    output[i][0] = i + 1


k = 0
for i in data:
    for j in range(i[0]):
        #金额相加
        output[i[j * 2 + 1] - 1][2] += i[j * 2 +2]
        #发红包扣钱
        output[k][2] -= i[j * 2 +2]
        #抢红包个数加1
        output[i[j * 2 + 1] - 1][1] += 1
    k += 1
#sorte()根据多个标准进行排序sorte(list,key = lambda s:(s[2],s[1],-s[0]))
#-s[0] 相反 reverse = True 设置为降序
newOutput = sorted(output,key = lambda s:(s[2],s[1],-s[0]),reverse = True)

for i in range(amountOfPeople):
    #print(i)
    print("{} {:.2f}".format(newOutput[i][0],newOutput[i][2]/100))
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘璐菲

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值