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 ...
随机推荐
- Oracle数据库常用监控语句
--在某个用户下找所有的索引 select user_indexes.table_name, user_indexes.index_name,uniqueness, column_name from ...
- ALS算法 (面试准备)
ALS算法描述: 1.ALS算法用来补全用户评分矩阵.由于用户评分矩阵比较稀疏,将用户评分矩阵进行分解,变成V和U的乘积.通过求得V和U两个小的矩阵来补全用户评分矩阵. 2.ALS算法使用交替最小二乘 ...
- cssrem 比例适配理解
cssrem只是帮你自动计算,省去了你在切图时,从设计稿拿到的px再根据比例转换成rem的中间过程. 这个40我无法猜测, 以前设计稿给的都是按640px(iphone5s的宽)来的,我们就按照这个比 ...
- css3+jQuery实现按钮水波纹效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...
- CheckBox复选框控件
CheckBox复选框控件 一.简介 1. 2.类结构图 二.CheckBox复选框控件使用方法 这里是使用java代码在LinearLayout里面添加控件 1.新建LinearLayout布局 2 ...
- CentOS下安装mysql及配置使用
最近一直使用的是CentOS,平时用的最多的数据库是Sql Server,对于mysql还停留在上学的时候,早已忘得一干二净,写这篇内容目的是,重新学习如何安装使用mysql. 一.安装mysql 操 ...
- 【scala】apply和update
我们在使用scala的时候经常会用到对象的apply方法和update方法. 虽然我们表面没有察觉,但是实际上两个方法都会遵循相关约定被调用. apply apply方法的约定:用括号传递给变量(对象 ...
- 017——VUE中v-fo指令的使用方法
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Qt DLL总结
(转自:http://qimo601.iteye.com/blog/1397936) QT动态链接库的调用方法,主要包括: 1.显式链接DLL,调用DLL的全局函数,采用Qt的QLibrary方法 2 ...
- flask 项目 部署服务器,package安装问题(无外网链接)
1.安装所需的环境/包 1) 在一台开发机器(有网络,编译成功)安装package: pipreqs 语法: pipreqs <项目路径> 将项目所使用的所有包目录将会导出至目录:requ ...