【2019暑期】【PAT乙级】1080 MOOC期终成绩 (25 分)

48 篇文章 0 订阅

复习
结构体

struct student{			//定义
	string a;
	int b;
};

bool my(student a,student b){		//自定义排序
	if(a.int == b.int) return a.string < b.string;
	else return a.int > b.int
}

sort(stu,stu+n,my);

map

map<string,string> a;
map<string,string>:iterator it;	//遍历
for(it = a.begin(); it != a.end(); it++){
	it -> second;
}

一开始直接用循环,超时,存储检查改用了map,不超时但是最后一个点报错,搞不懂,,理论都是对的,,
残缺代码

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
#include <cmath>
#include <map> 

using namespace std;

struct student{
	string name;
	double gp = 0;
	double gm = 0;
	double gfin = 0;
	double g = 0;
}; 

bool my(student a, student b){
	if(a.g == b.g) return a.name < b.name;
	return a.g > b.g;
}

int p,m,n;
student stu[110000];
	
int main(){
	
	cin >> p >> m >> n;
	map<string,student> t;
	for(int i=0; i<p; i++){
		string a;
		double b;
		cin >> a >> b;
		if(b >= 0 && b <= 900){
			t[a].name = a;
			t[a].gp = b;
		}
		
	}
	
	for(int i=0; i<m; i++){
		string a;
		double b;
		cin >> a >> b;
		if(b >= 0 && b <= 100){
			t[a].name = a;
			t[a].gm = b;
		}
		
	}
		
	for(int i=0; i<n; i++){
		string a;
		double b;
		cin >> a >> b;
		if(b >= 0 && b <= 100){
			t[a].name = a;
			t[a].gfin = b;
		}
	}
	
	map<string,student>::iterator it;
	int key = 0;
	for(it = t.begin(); it != t.end(); it++){
		stu[key] = it -> second;
		if(stu[key].gm > stu[key].gfin){
			stu[key].g = stu[key].gm * 0.4 + stu[key].gfin * 0.6;
			if(stu[key].g - (int)stu[key].g < 0.5)
				stu[key].g = (int)stu[key].g;
			else stu[key].g = (int)stu[key].g + 1 ;
		}		
		else
			stu[key].g = stu[key].gfin;
		key = key + 1;
	}

	sort(stu,stu+key,my);
	
	for(int i=0; i<key; i++){
		if(stu[i].g >= 60 && stu[i].gp >= 200 && stu[i].gfin != 0){
			if(stu[i].gm == 0) stu[i].gm = -1;
			cout << stu[i].name << " " << stu[i].gp << " ";
			cout << stu[i].gm << " " << stu[i].gfin << " ";
			cout << stu[i].g << endl;
		}
			
	}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值