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 ...
随机推荐
- ZC_异常
1. “Exception in thread "main" java.lang.UnsatisfiedLinkError: no JniVC6 in java.library.p ...
- thinkphp接收阿里淘宝客数据
坑在于淘宝客api返回的数据对象是SimpleXMLElement Object类型,不转为php的json array类型数据直接扔到thinkphp循环输出中会达不到要的效果,奇奇怪怪的数组,一度 ...
- jQuery EasyUI Datagrid VirtualScrollView视图简单分析
大家都知道EasyUI的Datagrid组件在加载大数据量时的优势并不是很明显,相对于其他一些框架,如果数据量达到几千,便会比较慢,特别是在IE下面.针对这种情况,我们首要做的是要相办法优化datag ...
- ie7 动态改变select option时,宽度自动变短解决方法
<html> <head> <title>JQuery</title> <meta http-equiv="pragma" c ...
- 解决:pipenv shell报错:AttributeError: 'module' object has no attribute 'run'
利用pipenv shell切换到虚拟环境时,显示报错:AttributeError: 'module' object has no attribute 'run' 可以看到是d:\program\p ...
- CodeForces - 197D
开场连wa三发A题,差点心态崩了,还好坚持打完了,一共A了三题 A题,判断能不能放第一个圆,能放的话,先手比赢 #include<map> #include<set> #inc ...
- InnoDB存储引擎的B+树索引算法
关于B+树数据结构 ①InnoDB存储引擎支持两种常见的索引. 一种是B+树,一种是哈希. B+树中的B代表的意思不是二叉(binary),而是平衡(balance),因为B+树最早是从平衡二叉树演化 ...
- LeetCode OJ:Merge Sorted Array(合并排序的数组)
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:Yo ...
- PostgreSQL流复制记录
参考了别人的部分,添加了自己在实践中的内容,仅做记录. 1.同步流复制中 主机操作 1.1postgresql.conf wal_level = hot_standby # 这个是设置主为wal的主机 ...
- Apache Tomcat Server Options 选项说明
Apache Tomcat Server Options 选项说明 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neu ...