原题链接:谁拿了最多奖学金
解题思路:
将每一位同学视为一个对象,对对象进行操作,思路简单;
在判断是否有相同奖学金时,所用方法有些麻烦。(若您有更简单的方法,望不吝赐教)
注意事项:
参考代码:
#include<iostream> #include<cmath> #include<iomanip> #include<algorithm> using namespace std; class Student { public: string name; int num; int average; //平均成绩 int appraisal;//评议成绩 char cadre;//学生干部 char west;//西部大学生 int quantity;//论文数量 int schoolship;//奖学金总额; Student() {//构造函数 this->name = ""; this->num = 0; this->average = 0; this->appraisal = 0; this->cadre = 0; this->west = 0; this->quantity = 0; this->schoolship = 0; } }; void schoolarship_shared(Student& stu) { if (stu.average > 80 && stu.quantity >= 1) stu.schoolship += 8000; if (stu.average > 85 && stu.appraisal > 80) stu.schoolship += 4000; if (stu.average > 90) stu.schoolship += 2000; if (stu.west == 'Y' && stu.average > 85) stu.schoolship += 1000; if (stu.cadre == 'Y' && stu.appraisal > 80) stu.schoolship += 850; } int main() { int n = 0; int sum = 0; cin >> n; Student* stu = new Student[n]; for (int i = 0; i < n; i++) { stu[i].num = i + 1; // 学号:如果有两位或两位以上的学生获得的奖金最多,输出他们之中在输入文件中出现最早的学生的姓名 cin >> stu[i].name >> stu[i].average >> stu[i].appraisal >> stu[i].cadre >> stu[i].west >> stu[i].quantity; schoolarship_shared(stu[i]); sum += stu[i].schoolship; } for (int i = 0; i < n; i++) { // 依据奖学金进行排序 for (int j = n-i - 1; j > i; j--) { if (stu[j].schoolship > stu[j - 1].schoolship) { Student temp = stu[j]; stu[j] = stu[j - 1]; stu[j - 1] = temp; } } } if (stu[0].schoolship == stu[1].schoolship) { //判断是否有相同奖学金的人; string temp; for (int i = 0; i < n-1; i++) { if (stu[i + 1].schoolship == stu[i].schoolship) { if (stu[i + 1].num < stu[i].num) temp = stu[i + 1].name; else temp = stu[i].name; } else break; } cout << temp << endl << stu[0].schoolship << endl << sum; } else { cout << stu[0].name << endl << stu[0].schoolship << endl << sum; } return 0; }
0.0分
0 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复