题意:排序题。

思路:通过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. BZOJ 1835 [ZJOI2010]base 基站选址:线段树优化dp

    传送门 题意 有 $ n $ 个村庄在一排直线上,现在要建造不超过 $ K $ 个通讯基站,基站只能造在村庄处. 第 $ i $ 个村庄距离第 $ 1 $ 个村庄的距离为 $ D_i $ .在此建造基 ...

  2. mysql 如果数据不存在,则插入新数据,否则更新 的实现方法

    CREATE TABLE `table_test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `my_key` int(11) NOT NULL DEFAULT ...

  3. MVVM4

    原地址(内容更丰富):http://www.cnblogs.com/888h/category/269092.html MVVM架构的简单解析   图1 View.ViewModel.Model之间的 ...

  4. ultraedit使用记录

    ultraedit使用记录 10:57:33 在日常的工作中,我经常用keil进行程序的编写等工作,不过在编写过程中Keil对中文的支持不是很好,容易发生问题:同事推荐我用ultraedit进行程序的 ...

  5. elementUI表格合并单元格

    相信你肯定看了 ElementUI 官方文档了,没看的话先去看下表格各个属性的意义,方便下文阅读:传送门 但你会发现此例过于简单,死数据,但我们开发的时候往往都是后台传递过来的数据,导致我们 rows ...

  6. 29-THREE.JS 根据公式画形状

    <!DOCTYPE html> <html> <head> <title></title> <script src="htt ...

  7. 【Java】方法的重载与重写

    一.方法的重载 1.概念 方法重载是指在一个类中定义多个同名的方法,但要求每个方法具有不同的参数的类型或参数的个数. 调用重载方法时,Java编译器能通过检查调用的方法的参数类型和个数选择一个恰当的方 ...

  8. 记vue+leaflet的一次canvas渲染爆栈

    背景: 在地图上绘制大量的circleMarker,leaflet能选择使用canvas来渲染,比起默认的svg渲染来说在大量绘制的情况下会更加流畅.但当触发其中某一个circleMarker的too ...

  9. Arcgis For Android之离线地图实现的几种方式

    为什么要用,我想离线地图的好处是不言而喻的,所以很多人做系统的时候都会考虑用离线地图.在此,我给大家介绍几种Arcgis For Android下加载离线地图的方式. 在Arcgis For Andr ...

  10. 实战JAVA 高并发设计

    一.同步(Synchronous)和异步(Asynchronous) 同步和异步通常用来形容一次方法调用,同步方法,调用者必须等到方法调用返回后,才能继续后续的行为,异步方法调用会立即返回,调用者就可 ...