PAT 1080 MOOC期终成绩 25分

题目:1080 MOOC期终成绩 - PAT (Basic Level) Practice (中文) (pintia.cn) 解析:80_哔哩哔哩_bilibili


思想

1.我们先用一个结构体存储状态,包括:学生id,线上成绩,期中成绩,期末成绩,总评成绩

2.我们依次读入学生id应对的线上成绩,期中成绩,期末成绩

3.计算总评成绩

graph TD Gmid_tern小于Gfinal时 --> Gmid_tern大于于Gfinal时

4.排序 输出顺序为按照总评分数(四舍五入精确到整数)递减。若有并列,则按学号递增。

5.输出 按照以下格式输出:学生学号 Gp​ Gmid−term​ Gfinal​ G


四舍五入Tips

2.5四舍五入我们可以先将其 <math xmlns="http://www.w3.org/1998/Math/MathML"> × 10 , + 5 ,最后再 / 10 ×10,+5,最后再/10 </math>×10,+5,最后再/10:

js 复制代码
2.5*10+5/10=(25+5)/10=30/10=3

同理,本题中我们也可以先 <math xmlns="http://www.w3.org/1998/Math/MathML"> ( G m i d − t e r n × 4 + G f i n a l × 6 + 5 ) / 10 (Gmid-tern ×4 + Gfinal×6+5)/10 </math>(Gmid−tern×4+Gfinal×6+5)/10

js 复制代码
#include<bits/stdc++.h>
using namespace std;

struct node
{
	string id;
	int a,b,c,avg;  //线上成绩,期中成绩,期末成绩,总评成绩 
}temp;

map<string,node>mp;  //用id映射状态 
vector<node>ans;
int p,m,n,score ;
string id;
	
bool cmp(node a,node b)
{
	//成绩不相同按照成绩排序,否则按照id的字典序升序 
	if(a.avg==b.avg)return a.id<b.id;
	return a.avg>b.avg;
}
int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(0);
	
     cin>>p>>m>>n;

	//输入线上 id,成绩 
	for(int i=0;i<p;i++) 
	{
		cin>>id>>score,mp[id].a=score,mp[id].b=-1,mp[id].c=-1;  //题目要求如果 无成绩输出-1,我们把没有输入的成绩初始化为-1 
	}
	//输入期中id,成绩 
	for(int i=0;i<m;i++) 
	{
		cin>>id>>score,mp[id].b=score;
	}
	//输入期末id,成绩 
	for(int i=0;i<n;i++) 
	{
		cin>>id>>score,mp[id].c=score;  
	}
	
	//遍历map 
	for(auto it=mp.begin();it!=mp.end();it++)
	{
		if(it->second.a<200)continue;  //如果线上编程成绩小于200,那么铁定不合格
	
	   //赋值 
		temp.id=it->first;	
		temp.a=it->second.a;
	    temp.b=it->second.b;
		temp.c=it->second.c;
		
		//如果期末成绩大于等于期中成绩  (注意是>=) 
		if(temp.c>=temp.b)temp.avg=temp.c; //那么期末成就是最终成绩 
		//否则就按照规则四舍五入 
		else temp.avg=(temp.b*4+temp.c*6+5)/10;
		
		//合格 注意是(>=) 
		if(temp.avg>=60)ans.push_back(temp); 
	} 
	
	sort(ans.begin(),ans.end(),cmp); 
	for(int i=0;i<ans.size();i++)
	{
		//输出id 线上成绩 期中成绩 期末成绩  总评成绩 
	cout<<ans[i].id; 
	   printf(" %d %d %d %d\n",ans[i].a,ans[i].b,ans[i].c,ans[i].avg);
	}
	return 0;
}
相关推荐
ValhallaCoder1 小时前
hot100-栈
数据结构·python·算法·
WW_千谷山4_sch5 小时前
洛谷B3688:[语言月赛202212]旋转排列(新解法:deque双端队列)
数据结构·c++·算法
Zachery Pole5 小时前
【代码随想录】二叉树
算法
漂流瓶jz5 小时前
UVA-11214 守卫棋盘 题解答案代码 算法竞赛入门经典第二版
c++·算法·dfs·aoapc·算法竞赛入门经典·迭代加深搜索·八皇后
浮生09196 小时前
DHUOJ 基础 88 89 90
算法
v_for_van6 小时前
力扣刷题记录7(无算法背景,纯C语言)
c语言·算法·leetcode
先做个垃圾出来………6 小时前
3640. 三段式数组 II
数据结构·算法
tankeven8 小时前
HJ93 数组分组
c++·算法
Σίσυφος19008 小时前
LM 在 PnP(EPnP / P3P)的应用
算法
陈天伟教授8 小时前
人工智能应用- 人工智能交叉:01. 破解蛋白质结构之谜
人工智能·神经网络·算法·机器学习·推荐算法