谁拿了最多奖学金

GitHub跳转原题关系图返回列表

按五条奖学金规则累计每名学生奖金,同时维护最高奖金和总奖金。

OJ: noi_openjudge

题目 ID: ch0109-04

难度:普及-

标签:模拟分类讨论python

日期: 2026-07-30 23:01

题意

按五项条件计算每位学生奖金,输出奖金最多的最早学生、其奖金和全体奖金总和。

思路

对每位学生分别判断五条规则并累加奖金。只在奖金严格更大时更新最高记录,因此并列时自然保留先输入的学生。

代码

Python代码

python
student_count = int(input())
best_name = ""
best_amount = -1
total_amount = 0

for _ in range(student_count):
    name, final_score_text, class_score_text, leader, west, paper_count_text = input().split()
    final_score = int(final_score_text)
    class_score = int(class_score_text)
    paper_count = int(paper_count_text)
    amount = 0
    amount += 8000 if final_score > 80 and paper_count >= 1 else 0
    amount += 4000 if final_score > 85 and class_score > 80 else 0
    amount += 2000 if final_score > 90 else 0
    amount += 1000 if final_score > 85 and west == "Y" else 0
    amount += 850 if class_score > 80 and leader == "Y" else 0
    total_amount += amount
    if amount > best_amount:
        best_name, best_amount = name, amount

print(best_name)
print(best_amount)
print(total_amount)

C++代码

cpp
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;



int n;
struct _stu {
    char name[30];
    int qimo_chengji;
    int bianji_chengji;
    char ganbu;
    char xibu;
    int lunwen;
};

_stu stu[105];

void init(){
    
    scanf("%d",&n);
    int i;
    for (i=1;i<=n;i++){
        scanf("%s %d %d %c %c %d",stu[i].name, &stu[i].qimo_chengji, &stu[i].bianji_chengji, &stu[i].ganbu, &stu[i].xibu, &stu[i].lunwen);
        //printf("%s %d %d %c %c %d\n",stu[i].name, stu[i].qimo_chengji, stu[i].bianji_chengji, stu[i].ganbu, stu[i].xibu, stu[i].lunwen);
    }
}


int get_fen(int i){
    int t = 0;
    _stu &s = stu[i];
    if( s.qimo_chengji >80 && s.lunwen >=1)
        t+=8000;
    if( s.qimo_chengji > 85 && s.bianji_chengji>80)
        t+=4000;
    if(s.qimo_chengji > 90)
        t+=2000;
    if(s.qimo_chengji>85 && s.xibu=='Y')
        t+=1000;
    if(s.bianji_chengji > 80 && s.ganbu == 'Y')
        t+=850;
    return t;
}

int main(){
    init();
    int i;
    int m = -1;
    int idx;
    int all = 0;
    for (i=1;i<=n;i++){
        int t=  get_fen(i);
        all+=t;
        if( m < t){
            m = t;
            idx = i;
        }
    }

    printf("%s\n%d\n%d",stu[idx].name,m,all);
    
    return 0;
}

复杂度

时间复杂度为 O(n)O(n),额外空间复杂度为 O(1)O(1)

总结

多条件累计题应把每项奖金的判断独立写出。