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_io__BIO_NIO_AIO
1. http://stevex.blog.51cto.com/4300375/1284437 http://www.cnblogs.com/zhuYears/archive/2012/09/28/2 ...
- crm开发(基于ssh)(五)
1 信息查询 (1)多条件组合查询 -拼接hql语句 -使用离线对象 2 添加数据字典表 (1)改造添加客户功能 3 统计分析 (1)调用普通sql实现 (2)结果处理操作 4 使用ssh注解整合 ( ...
- Ajax基础(三)--eval的使用
eval的使用: 1.定义和用法 计算某个字符串,并执行其中的js代码 eval(string) string必须,含有表达式或执行语句 string有返回值的话 2.实例 2.1 字符串上该用eva ...
- os.path.abs()与os.path.realpath()的一点区别
相同点 1. 两者都是返回绝对路径,如果参数path为空,则返回当前文件所在目录的绝对路径 当前py文件所在的目录是revise print(os.path.abspath("") ...
- oepnstack笔记
openstack简介: 组件:Nova 提供计算资源池neutron 网络资源管理horizon 基于openstack API借口使用django开发的web管理 组件:Nova 提供计算资源池n ...
- Hosts文件路径及修改方法
(转自:http://www.techolics.com/softdev/20111029_100.html) 什么是Hosts文件? 根据百度百科的定义,Hosts文件是一个系统文件,这是一个本地的 ...
- 通过TortoiseSVN checkout的文件前面没有“状态标识”
问题描述:安装完成VisualSVN Server.VisualSVn和TortoiseSVN后,然后通过SVN Server新建Repository(仓库),用Visual Studio新建一个So ...
- POJ1251 Jungle Roads
解题思路:看懂题意是关键,Kruskal算法,最小生成树模板. 上代码: #include<cstdio> #include<cstring> #include<algo ...
- tab显示不同数据
效果 核心代码 [js] [#escape x as (x)!?html]<!doctype html><html lang="zh-CN"><hea ...
- MYSQL 级联 添加外键
MySQL支持外键的存储引擎只有InnoDB,在创建外键的时候,要求父表必须有对应的索引,子表在创建外键的时候也会自动创建对应的索引.在创建索引的时候,可以指定在删除.更新父表时,对子表进行的相应操作 ...