PAT甲组1137 Final Grading思路解析和代码

A1137

题目链接

个人思路

本题属于模拟题,按题目要求使用结构体排序即可
注意数组大小不能只开到10010,可能P,M,N中包含的用户各不相同,应该开到30000,否则最后一个测试点会出现段错误

英文理解
The final grade is calculated by G=(G​mid−term​​ × 40% + G​final ​​× 60%) if G​mid−term​​ > G​final​​, or G​final ​​will be taken as the final grade G.
if条件句后置,当Gm > Gf,按4:6计算

个人思路代码

#include <bits/stdc++.h>
using namespace std;
const int maxn = 30010;
int P, M, N;
struct Student{
	string name;
	double Gp = -1;
	double Gm = -1;
	double Gf = -1;
	double G = -1;//总分G 
}stu[maxn];
unordered_map<string, int> mp;//名字与下标的映射 
bool cmp(Student s1, Student s2)
{
	if(s1.G != s2.G)
		return s1.G > s2.G;
	else
		return s1.name < s2.name;
}
int main(int argc, char *argv[]) {
	scanf("%d%d%d", &P, &M, &N);
	for(int i = 0; i < P; ++i)
	{
		cin >> stu[i].name >> stu[i].Gp;
		mp[stu[i].name] = i;
	}
	//存在新输入的用户 
	int pos = P;
	for(int i = 0; i < M; ++i)
	{
		string nn;
		int ss;
		cin >> nn >> ss;
		if(mp.count(nn) == 0)//新用户 
		{
			stu[pos].name = nn;
			stu[pos].Gm = ss;
			mp[nn] = pos++;
		}
		else
		{
			int id = mp[nn];
			stu[id].Gm = ss;
		}
	}
	for(int i = 0; i < N; ++i)
	{
		string nn;
		int ss;
		cin >> nn >> ss;
		if(mp.count(nn) == 0)//新用户 
		{
			stu[pos].name = nn;
			stu[pos].Gf = ss;
			mp[nn] = pos++;
		}
		else
		{
			int id = mp[nn];
			stu[id].Gf = ss;
		}
	}
	//cout << endl;
	for(int i = 0; i < pos; ++i)
	{
		if(stu[i].Gm > stu[i].Gf)
			stu[i].G = 0.4 * stu[i].Gm + 0.6 * stu[i].Gf;
		else
			stu[i].G = stu[i].Gf;
		
		stu[i].G = round(stu[i].G);	
		//cout << stu[i].name << " " << stu[i].G << endl;
	}
	sort(stu, stu + pos, cmp);
	for(int i = 0; i < pos; ++i)
	{
		if(stu[i].Gp >= 200 && stu[i].G >= 60)
			cout << stu[i].name << " " << stu[i].Gp << " " << stu[i].Gm << " " << stu[i].Gf << " " << stu[i].G << endl;
	}
	
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值