C++版浙大PAT乙级1080(25分)

https://pintia.cn/problem-sets/994805260223102976/problems/994805261493977088

这题用了map来通过名字找编号。一开始没想到用结构体和sort,用了几个数组和快速排序,我好笨,浪费了好多时间。

#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

struct person{
	string name;
	int p=-1;
	int m=-1;
	int n=-1;
	int g=-1;
}stus[10001];

bool cmp(person a, person b){
	if(a.g != b.g){
		return a.g>b.g;
	}else{
		return a.name<b.name;
	}
}

int main() {
	float temp;
	int p, m, n, score, num=1;
	cin >> p >> m >> n;
	string str, name[10000];
	map<string, int> student;
	// 编程
	for(int i=1; i<=p; i++){
		cin >> str >> score;
		if(score>=200){
			student[str] = num;
			stus[num].name = str;
			stus[num].p = score;
			num ++;
		}
	}
	// 期中
	for(int i=1; i<=m; i++){
		cin >> str >> score;
		if(student[str]>=1){
			stus[student[str]].m = score;
		}
	}
	// 期末
	for(int i=1; i<=n; i++){
		cin >> str >> score;
		if(student[str]>=1){
			stus[student[str]].n = score;
			// 总评
			if(score >= stus[student[str]].m){
				stus[student[str]].g = score;
			}else{
				temp = score*0.6+stus[student[str]].m*0.4;
				stus[student[str]].g = (int)(temp+0.5);
			}
		}
	}
	// 排序
	sort(stus+1, stus+num+1, cmp);
	// 打印
	for(int i=1; i<num; i++){
		if(stus[i].g >= 60){
			cout << stus[i].name << " ";
			cout << stus[i].p << " ";
			cout << stus[i].m << " ";
			cout << stus[i].n << " ";
			cout << stus[i].g << endl;
		}
	}
    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值