c++代码完成:题目描述】某校的惯例是在每学期的期末考试之后发放奖学金。发放的奖学金共有五种获取的条件各自不同:1院士奖学金每人8000元期末平均成绩高于80分80并且在本学期内发表1篇或1篇以上论文的学生均可获得;2五四奖学金每人4000元期末平均成绩高于85分85并且班级评议成绩高于80分80的学生均可获得;3成绩优秀奖每人2000元期末平均成绩高于90分90的学生均可获得;4西部奖学金每人1
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Student {
string name;
int avgScore;
int evalScore;
bool isCadre;
bool isWestern;
int paperNum;
int scholarship;
};
bool compare(Student s1, Student s2) {
return s1.scholarship > s2.scholarship;
}
int main() {
int N;
cin >> N;
vector<Student> students(N);
for (int i = 0; i < N; i++) {
cin >> students[i].name >> students[i].avgScore >> students[i].evalScore
>> students[i].isCadre >> students[i].isWestern >> students[i].paperNum;
students[i].scholarship = 0;
}
for (int i = 0; i < N; i++) {
if (students[i].avgScore > 80 && students[i].paperNum >= 1) {
students[i].scholarship += 8000;
}
if (students[i].avgScore > 85 && students[i].evalScore > 80) {
students[i].scholarship += 4000;
}
if (students[i].avgScore > 90) {
students[i].scholarship += 2000;
}
if (students[i].avgScore > 85 && students[i].isWestern) {
students[i].scholarship += 1000;
}
if (students[i].evalScore > 80 && students[i].isCadre) {
students[i].scholarship += 850;
}
}
sort(students.begin(), students.end(), compare);
cout << students[0].name << endl;
cout << students[0].scholarship << endl;
int totalScholarship = 0;
for (int i = 0; i < N; i++) {
totalScholarship += students[i].scholarship;
}
cout << totalScholarship << endl;
return 0;
}
``
原文地址: http://www.cveoy.top/t/topic/ib4z 著作权归作者所有。请勿转载和采集!