LzzzOnly


私信TA

用户名:uq_62513724447

访问量:470

签 名:

等  级
排  名 818
经  验 3557
参赛次数 0
文章发表 5
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:

                将每一位同学视为一个对象,对对象进行操作,思路简单;

                在判断是否有相同奖学金时,所用方法有些麻烦。(若您有更简单的方法,望不吝赐教)

注意事项:

参考代码:

#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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区