算法
(模拟,枚举) $O(n)$
首先枚举每个同学,对于每个同学依次判断是否可以获得各个奖项,统计出该同学可以获得的总奖金数。
然后循环找出最靠前获的奖金数量最多的同学即可。
时间复杂度
每个同学只会被处理常数次,所以总时间复杂度是 $O(n)$。
C++ 代码
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 110;
int n;
struct Person
{
string name;
int final_score, class_score;
char is_cadre, is_west;
int papers;
int money;
}p[N];
int get_money(Person a)
{
int res = 0;
if (a.final_score > 80 && a.papers) res += 8000;
if (a.final_score > 85 && a.class_score > 80) res += 4000;
if (a.final_score > 90) res += 2000;
if (a.final_score > 85 && a.is_west == 'Y') res += 1000;
if (a.class_score > 80 && a.is_cadre == 'Y') res += 850;
return res;
}
int main()
{
cin >> n;
int sum = 0;
for (int i = 0; i < n; i ++ )
{
cin >> p[i].name;
cin >> p[i].final_score >> p[i].class_score;
cin >> p[i].is_cadre >> p[i].is_west;
cin >> p[i].papers;
p[i].money = get_money(p[i]);
sum += p[i].money;
}
int t = 0;
for (int i = 1; i < n; i ++ )
if (p[i].money > p[t].money)
t = i;
cout << p[t].name << endl;
cout << p[t].money << endl;
cout << sum << endl;
return 0;
}