解题思路:
将每一位同学视为一个对象,对对象进行操作,思路简单;
在判断是否有相同奖学金时,所用方法有些麻烦。(若您有更简单的方法,望不吝赐教)
注意事项:
参考代码:
#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++代码)(大数加法)浏览:1008 |
C语言程序设计教程(第三版)课后习题6.6 (C语言代码)浏览:626 |
C语言程序设计教程(第三版)课后习题5.7 (Java代码)浏览:910 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:541 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:910 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:688 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:583 |
字符逆序 (C语言代码)浏览:506 |
马拦过河卒 (C语言代码)浏览:1213 |
C语言训练-斐波纳契数列 (C语言代码)浏览:644 |