OJ_学生信息系统

题干

题干

输入样例:

5
zhaoyi 70 80 90 240
qianer 65 32 77 174
sunsan 100 55 68 223
lisi 86 77 90 253
wangwu 100 59 66 225

输出样例:

*[qianer] 65 32 77
*[sunsan] 100 55 68
*[wangwu] 100 59 66
lisi 86 77 90
zhaoyi 70 80 90
wangwu 100 59 66
sunsan 100 55 68
qianer 65 32 77

C++实现

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

struct student {
	char name[10];
	int one;  //第一科成绩
	int two; 
	int three;
	int total; //总成绩
	bool flag;//是否挂科
};

bool cmp(student a, student b) {
	都是3科,平均成绩越高总成绩就越高,所以只需比较总成绩
	return a.total > b.total;
}

int main() {
	int N;

	//读入学生信息
	while (cin >> N) {
		vector<student> s;
		for (int i = 0; i < N; i++)
		{
			student t;
			cin >> t.name >> t.one >> t.two >> t.three >> t.total;
			if (t.one < 60 || t.two < 60 || t.three < 60) {
				t.flag = false;//挂科则为false
			}
			else {
				t.flag = true;
			}
			s.push_back(t);
		}

		//如果挂科了
		for (int i = 0; i < s.size(); i++)
		{
			if (!s[i].flag) {
				cout << "*[" << s[i].name << "]";
				cout << " " << s[i].one << " " << s[i].two << " " << s[i].three << endl;
			}
		}

		sort(s.begin(), s.end(), cmp);

		for (int i = 0; i < s.size(); i++)
		{
			cout << s[i].name;
			cout << " " << s[i].one << " " << s[i].two << " " << s[i].three << endl;
		}
	}
	
	return 0;
}

  • 7
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值