c++目描述
CZ中学每学期都会给学生提供丰厚的奖学金,但是要想获得这些奖学金也不是一件容易的事情。CZ中学对学生成绩的评定一共有A、B、C共3个等级,提供的奖学金有如下几种:
A等奖学金: 总分大于等于285分,且语数英三门课的成绩均在90分以上,奖金3000元 ;
B等奖学金: 总分大于等于280分,且语数英三门课的成绩均在88分以上,奖金2000元 ;
C等奖学金: 总分大于等于275分,且语数英三门课的成绩均在85分以上,奖金1000元 ;
所有未获得奖学金的一律设置为“M”等,且奖金设为0;
在CZ中学初三(2)班共有n个学生(姓名为汉字的全拼,并且无空格)(n<10),请根据他们的成绩按照总分的高低次序,如总分相同则按照语文成绩的高低进行输出获得奖学金同学的名字、等地及金额。
输入
5
xiaoming 95 90 62
xiaoli 88 96 98
xiaozhang 86 90 89
xiaozhu 90 90 90
xiaowang 98 95 96
输出
xiaowang A 3000
xiaoli B 2000
样例
输入 复制
5
xiaoming 95 90 62
xiaoli 88 96 98
xiaozhang 86 90 89
xiaozhu 90 90 90
xiaowang 98 95 96
输出 复制
xiaowang A 3000
xiaoli B 2000
#include <iostream>
#include <string>
using namespace std;
struct Student {
string name;
int chinese;
int math;
int english;
int total;
string level;
int scholarship;
};
void calculateScholarship(Student& student) {
if (student.total >= 285 && student.chinese >= 90 && student.math >= 90 && student.english >= 90) {
student.level = "A";
student.scholarship = 3000;
} else if (student.total >= 280 && student.chinese >= 88 && student.math >= 88 && student.english >= 88) {
student.level = "B";
student.scholarship = 2000;
} else if (student.total >= 275 && student.chinese >= 85 && student.math >= 85 && student.english >= 85) {
student.level = "C";
student.scholarship = 1000;
} else {
student.level = "M";
student.scholarship = 0;
}
}
int main() {
int n;
cin >> n;
Student students[n];
for (int i = 0; i < n; i++) {
cin >> students[i].name >> students[i].chinese >> students[i].math >> students[i].english;
students[i].total = students[i].chinese + students[i].math + students[i].english;
calculateScholarship(students[i]);
}
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < n-1-i; j++) {
if (students[j].total < students[j+1].total) {
swap(students[j], students[j+1]);
} else if (students[j].total == students[j+1].total && students[j].chinese < students[j+1].chinese) {
swap(students[j], students[j+1]);
}
}
}
for (int i = 0; i < n; i++) {
if (students[i].scholarship > 0) {
cout << students[i].name << " " << students[i].level << " " << students[i].scholarship << endl;
}
}
return 0;
}