1137 Final Grading
题意:排序题。
思路:通过unordered_map来存储考生姓名与其成绩信息结构体的映射,成绩初始化为-1,在读入数据时更新各个成绩,最后计算最终成绩并把符合条件的学生存入vector,再排序即可。需要注意的是,计算最终成绩时记得"G must be rounded up to an integer"。关于取整函数,总结在这里。
代码:
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <fstream>
using namespace std;
struct Student{
string id;
int Gp,Gm,Gf,Gtot;
Student():id(),Gm(-),Gf(-),Gtot(){}
};
unordered_map<string,Student> mp;
vector<Student> stu;
bool cmp(Student a,Student b)
{
if(a.Gtot!=b.Gtot) return a.Gtot>b.Gtot;
else return a.id<b.id;
}
int main()
{
//ifstream cin("pat.txt");
int p,m,f;
cin>>p>>m>>f;
string id;
int score;
;i<p;i++){
cin>>id>>score;
mp[id].id=id;
mp[id].Gp=score;
}
;i<m;i++){
cin>>id>>score;
mp[id].id=id;
mp[id].Gm=score;
}
;i<f;i++){
cin>>id>>score;
mp[id].id=id;
mp[id].Gf=score;
}
for(auto it:mp){
Student st=it.second;
if(st.Gm>st.Gf) st.Gtot=round(st.Gm*0.4+st.Gf*0.6);//注意四舍五入
else st.Gtot=st.Gf;
&& st.Gtot>=) stu.push_back(st);
}
sort(stu.begin(),stu.end(),cmp);
for(auto it:stu)
cout<<it.id<<" "<<it.Gp<<" "<<it.Gm<<" "<<it.Gf<<" "<<it.Gtot<<"\n";
;
}
1137 Final Grading的更多相关文章
- PAT 1137 Final Grading[一般][排序]
1137 Final Grading(25 分) For a student taking the online course "Data Structures" on China ...
- PAT 甲级 1137 Final Grading
https://pintia.cn/problem-sets/994805342720868352/problems/994805345401028608 For a student taking t ...
- 1137 Final Grading (25 分)
For a student taking the online course "Data Structures" on China University MOOC (http:// ...
- PAT 1137 Final Grading
For a student taking the online course "Data Structures" on China University MOOC (http:// ...
- PAT_A1137#Final Grading
Source: PAT A1137 Final Grading (25 分) Description: For a student taking the online course "Dat ...
- A1137. Final Grading
For a student taking the online course "Data Structures" on China University MOOC (http:// ...
- PAT A1137 Final Grading (25 分)——排序
For a student taking the online course "Data Structures" on China University MOOC (http:// ...
- PAT甲级——A1137 Final Grading【25】
For a student taking the online course "Data Structures" on China University MOOC (http:// ...
- PTA 1139 1138 1137 1136
PAT 1139 1138 1137 1136 一个月不写题,有点生疏..脑子跟不上手速,还可以啦,反正今天很开心. PAT 1139 First Contact 18/30 找个时间再修bug 23 ...
随机推荐
- Java多线程 - 线程同步
多线程操作同一个对象时,容易引发线程安全问题.为了解决线程安全问题,Java多线程引入了同步监视器. 同步代码块 同步代码块语法格式如下: synchronized(obj){ //此处的代码即为同步 ...
- 用Heartbeat实现HA集群
HA即高可用(high avaliable),又被叫做双机热备,用于关键性业务,简单理解就是,有两台机器A和B,正常是A提供服务,B待机闲置,当A宕机或服务宕掉,会切换到B机器继续提供服务.常用实现高 ...
- 栈的基本操作--java实现
package com.wyl.linklist; /** * 栈的定义及相关操作 * 用数组实现栈 * 栈是一个线性表,不过进栈和出栈操作在表尾操作 * @author wyl * */ publi ...
- 2012 Multi-University Training Contest 7
2012 Multi-University Training Contest 7 A.As long as Binbin loves Sangsang B.Dead or alive C.Dragon ...
- selenium学习笔记(智能等待)
博主在尝试对百度首页用selenium完成自动登录的功能 反复多次尝试元素定位方法也未写错.最后发现问题原因: 脚本运行速度快于页面加载速度 如百度首页登录例子.脚本已经开始寻找登录弹窗 但是页面仍在 ...
- 移动国家号(MCC)
定义移动国家号 Mobile Country Code (MCC)由三位十进制数组成,它表明移动用户(或系统)归属的国家. 格式移动国家号(MCC)由三个十进制数组成,编码范围为十进制的000-999 ...
- 【spark】SparkSession的API
SparkSession是一个比较重要的类,它的功能的实现,肯定包含比较多的函数,这里介绍下它包含哪些函数. builder函数public static SparkSession.Builder b ...
- Oracle的导出和导入
(摘自:http://www.cnblogs.com/mchina/archive/2012/09/12/2678093.html) 数据库的备份操作是在整个项目运行中最重要的工作之一. 一.数据的导 ...
- 【git】不同协议的路径
https https://github.com/yesuuu/ganLearn.git ssh git@github.com:yesuuu/ganLearn.git git@idc:ganLearn ...
- 项目工程结构说明(Internal)
注意:想要彻底把Internal关键字搞清楚,就耐着性子把她读完.当然了这篇文章只是对其他文章的总结.也算是引用吧.主要还是为了把知识点搞清楚 进入主题之前先来了解一下,项目.解决方案.程序集.命名空 ...