洛谷P1051Python写法(2种)

本文分享了两种使用Python解答洛谷P1051问题的方法,供编程爱好者参考学习。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一种:

info = list()
money = 0
ans = 0
total = 0
for i in range(int(input())):
    info = list(input().split(" "))
    if int(info[1])>80 and int(info[5])>=1:
        money+=8000
    if int(info[1])>85 and int(info[2])>80:
        money+=4000
    if int(info[1])>90:
        money+=2000
    if int(info[1])>85 and info[4]=='Y':
        money+=1000
    if int(info[2])>80 and info[3]=='Y':
        money+=850
    if money > ans:
        ans = money
        name = info[0]
    total+=money
    money = 0
print(name)
print(ans)
print(total)

第二种:

def optiontobool(ch, yes='Y', no='N'):
    if ch == yes:
        return True
    elif ch == no:
        return False
class Student:
    def __init__(self,
                 name: str,
                 qm: int,
                 bj: int,
                 gb,
                 xb,
                 lw: int,
                 yes='Y',
                 no='N'):
        self.name = name
        self.qm = qm
        self.bj = bj
        if type(gb) == bool:
            self.gb = gb
        else:
            self.gb = optiontobool(gb, yes, no)
        if type(xb) == bool:
            self.xb = xb
        else:
            self.xb = optiontobool(xb, yes, no)
        self.lw = lw
        self.jxj = self.getjxj()
    def getjxj(self):
        jxj = 0
        if self.qm > 80 and self.lw > 0:
            jxj += 8000
        if self.qm > 85 and self.bj > 80:
            jxj += 4000
        if self.qm > 90:
            jxj += 2000
        if self.qm > 85 and self.xb:
            jxj += 1000
        if self.bj > 80 and self.gb:
            jxj += 850
        return jxj
def main():
    n = int(input())
    stu = []
    tot_money = 0
    data = input().split()
    data[1] = int(data[1])
    data[2] = int(data[2])
    data[5] = int(data[5])
    stu.append(Student(*data))
    stu_max = stu[0]
    stu_index = 0
    tot_money += stu[0].jxj
    for i in range(1, n):
        data = input().split()
        data[1] = int(data[1])
        data[2] = int(data[2])
        data[5] = int(data[5])
        stu.append(Student(*data))
        if stu[i].jxj > stu_max.jxj:
            stu_max = stu[i]
            stu_index = i
        tot_money += stu[i].jxj
    print(stu_max.name)
    print(stu_max.jxj)
    print(tot_money)
if __name__ == '__main__':
    main()

大家借鉴。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值