1080 MOOC期终成绩 (25分) C++ PAT (Basic Level) Practice (中文)

利用unordered_map存储学生成绩信息,vector存储学生姓名 。
通过输入的各项成绩进行筛选,不符合的直接跳过,最后进行排序输出(对vector进行排序,比较项为map中存储的学生成绩信息)。在这里插入图片描述

#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>

using namespace std;

struct stu
{
	int Gp, Gm = -1, Gf, Gs;
};

unordered_map<string, stu>s;

vector<string>ID;

bool cmp(string a,string b){return s[a].Gs > s[b].Gs || (s[a].Gs == s[b].Gs && a < b);}

int main(void)
{
	int P, N, M, G;
	char name[21];
	scanf("%d %d %d", &P, &N, &M);

	for (int i = 0; i < P; i++) {  //在线编程成绩Gp  小于200直接舍弃
		scanf("%s %d", name, &G);
		if (G >= 200) {
			s[name].Gp = G;
		}
	}

	for (int i = 0; i < N; i++) {  //其中考试成绩Gmid_team  当Gp合格才会记录
		scanf("%s %d", name, &G);
		if (s.find(name) != s.end()) {
			s[name].Gm = G;
		}
	}

	for (int i = 0; i < M; i++) {
		scanf("%s %d", name, &G);
		if (s.find(name) != s.end()) {
			s[name].Gf = G;
			if (G < s[name].Gm) s[name].Gs = (int)((float)s[name].Gm * 0.4 + (float)G * 0.6 + 0.5);
			else s[name].Gs = G;

			if (s[name].Gs < 60)s.erase(name);   //如果最终成绩小于60  直接删掉
			else ID.push_back(name);			 //大于等于60  放入合格数组 等着排序
		}
	}

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

	for (auto i: ID) {
		printf("%s %d %d %d %d\n", i.c_str(), s[i].Gp, s[i].Gm, s[i].Gf, s[i].Gs);
	}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值