题意:排序题。

思路:通过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的更多相关文章

  1. PAT 1137 Final Grading[一般][排序]

    1137 Final Grading(25 分) For a student taking the online course "Data Structures" on China ...

  2. PAT 甲级 1137 Final Grading

    https://pintia.cn/problem-sets/994805342720868352/problems/994805345401028608 For a student taking t ...

  3. 1137 Final Grading (25 分)

    For a student taking the online course "Data Structures" on China University MOOC (http:// ...

  4. PAT 1137 Final Grading

    For a student taking the online course "Data Structures" on China University MOOC (http:// ...

  5. PAT_A1137#Final Grading

    Source: PAT A1137 Final Grading (25 分) Description: For a student taking the online course "Dat ...

  6. A1137. Final Grading

    For a student taking the online course "Data Structures" on China University MOOC (http:// ...

  7. PAT A1137 Final Grading (25 分)——排序

    For a student taking the online course "Data Structures" on China University MOOC (http:// ...

  8. PAT甲级——A1137 Final Grading【25】

    For a student taking the online course "Data Structures" on China University MOOC (http:// ...

  9. PTA 1139 1138 1137 1136

    PAT 1139 1138 1137 1136 一个月不写题,有点生疏..脑子跟不上手速,还可以啦,反正今天很开心. PAT 1139 First Contact 18/30 找个时间再修bug 23 ...

随机推荐

  1. EF6 Code First 系列 (四):SQLite的DropCreateDatabaseIfModelChanges和乐观并发控制

    没什么好说的,能支持DropCreateDatabaseIfModelChanges和RowVersion的Sqlite谁都想要.EntityFramework7正在添加对Sqlite的支持,虽然EF ...

  2. .NET、C#和ASP.NET三者之间的区别与联系

    .NET.C#和ASP.NET三者之间的区别与联系 1..net(dot net) .net是一个平台,抽象的平台概念. 实现形式是库:①定义了基本的类型(通用类型系统CTS,common type ...

  3. neutron之SDN简单测试

    title: Neutron SDN 手动实现手册 date: 2017-04-13 23:37 tags: Network 本文旨在通过自己搭建类似neutron (openvswitch + gr ...

  4. Linux安全运维笔记2018-03-01更新

    本人wechat:YWNlODAyMzU5MTEzMTQ=. *** # 修改关键目录文件的权限 chmod u-x,g-r /home/lema chmod 444 /home/lema # 用户权 ...

  5. UI-UIScrollView

    - (void)viewDidLoad { [super viewDidLoad]; scrollView = [[UIScrollView alloc] initWithFrame:CGRectMa ...

  6. C#当中利用Attribute实现简易AOP

    首先看一段简单的代码: public partial class Form1 : Form { public Form1() { InitializeComponent(); } //来自UI层的调用 ...

  7. HAWQ取代传统数仓实践(八)——维度表技术之角色扮演维度

    单个物理维度可以被事实表多次引用,每个引用连接逻辑上存在差异的角色维度.例如,事实表可以有多个日期,每个日期通过外键引用不同的日期维度,原则上每个外键表示不同的日期维度视图,这样引用具有不同的含义.这 ...

  8. [置顶] 个人博客上线!欢迎来访~ http://onlyloveyd.cn/

    简介 Hexo + Github + 个人域名 构建静态博客系统. 构建方法 参考 https://yq.aliyun.com/articles/64953 个人博客网站 Cherish Androi ...

  9. LINUX命令—让人喜爱的find

    FIND命令的让人喜爱的地方在于其后面跟着的 –exec  可以执行其他linux命令 这点太让人高兴了,不过他的结尾要带一个特殊的结构 {} \: 说说实例:

  10. SQLServer流水号自动生成

    最近给客户做生成条码的功能时,碰到个问题,需要根据数量自动生成流水号,然后加上客户指定的前缀,组合成条码. 折腾了一会,最后通过个存储过程实现. --@Prefix 指定前缀,@InitialVal ...