本题只需要把每个人的信息按照题目要求判断一下,可以获得哪些奖项的奖学金,最后把每个人获得的奖学金统计一下,用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; }