跳到正文

题解

题解:P1051 [NOIP 2005 提高组] 谁拿了最多奖学金

afo_subway约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
题目
P1051

版本

  1. v1当前

本题只需要把每个人的信息按照题目要求判断一下,可以获得哪些奖项的奖学金,最后把每个人获得的奖学金统计一下,用sort排序一下,输出奖学金最多的人的信息即可。 Code: #include <bits/stdc++.h> using namespace std;

struct stu { string name; int ave, pycj, lunwen, jxj, no; char xsgb, xbsf; };

stu a[105];

bool cmp(stu x,stu y) { if (x.jxj > y.jxj) return true; else if (x.jxj == y.jxj && x.no < y.no) return true; else return false; }

int main() { int n, sum = 0; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i].name; cin >> a[i].ave; cin >> a[i].pycj; cin >> a[i].xsgb; cin >> a[i].xbsf; cin >> a[i].lunwen; if (a[i].ave > 80 && a[i].lunwen >= 1) a[i].jxj += 8000; if (a[i].ave > 85 && a[i].pycj > 80) a[i].jxj += 4000; if (a[i].ave > 90) a[i].jxj += 2000; if (a[i].ave > 85 && a[i].xbsf == ‘Y’) a[i].jxj += 1000; if (a[i].pycj > 80 && a[i].xsgb == ‘Y’) a[i].jxj += 850; sum += a[i].jxj; a[i].no = i; } sort(a + 1, a + n + 1, cmp); cout << a[1].name << endl << a[1].jxj << endl << sum; return 0; }

原文