题意:排序题。

思路:通过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. LeetCode第[15]题(Java):3Sum (三数之和为目标值)——Medium

    题目难度:Medium 题目: Given an array S of n integers, are there elements a, b, c in S such that a + b + c  ...

  2. mysql 修改编码格式

    下载了mysql的客户端,一般其默认的编码格式是gbk,为了方便后续使用,想要将其编码格式改为utf8. 这时候的方法是: 1.进入mysql的安装目录,找到my.ini文件. 2.以txt文件的格式 ...

  3. python基础7 - 函数

    1. 函数的快速体验 所谓函数,就是把 具有独立功能的代码块 组织为一个小模块,在需要的时候 调用 函数的使用包含两个步骤: 定义函数 —— 封装 独立的功能 调用函数 —— 享受 封装 的成果 函数 ...

  4. ubuntu14.04搭建Hadoop2.9.0伪分布式环境

    本文主要参考 给力星的博文——Hadoop安装教程_单机/伪分布式配置_Hadoop2.6.0/Ubuntu14.04 一些准备工作的基本步骤和步骤具体说明本文不再列出,文章中提到的“见参考”均指以上 ...

  5. 51nod 1326 奇妙的spfa+dp

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1326 1326 遥远的旅途 题目来源: TopCoder 基准时间限制: ...

  6. 用phpexcel插件导出excel2003

    ob_end_clean();//清空缓冲区并关闭输出缓冲(清除脏数据). header('Content-Type:application/vnd.ms-execel'); header('Cont ...

  7. 查看SQLServer的最大连接数

    如何查看SQLServer的最大连接数?相信很多人对个很有兴趣,一下就给出两种方法: 1. 查询服务器属性 默认服务设置为0(表示不受限制). 2. SQL查看最大连接数 这里的32767就是服务器的 ...

  8. IOS-推送通知

    一.推送通知 注意:这里说的推送通知跟NSNotification有所区别 NSNotification是抽象的,不可见的 推送通知是可见的(能用肉眼看到)   iOS中提供了2种推送通知 本地推送通 ...

  9. MongoDB架构——记得结合前面的文章看,里面的图画的很好

    转自:http://www.ha97.com/4580.html 本文图片来自Ricky Ho的博文MongoDB构架(MongoDB Architecture),这是个一听就感觉很宽泛的话题,但是作 ...

  10. Mac PyCharm专业版破解

    1. 先在PyCharm官网:http://www.https://www.jetbrains.com/pycharm/,下载PyCharm专业版安装包 2. 安装PyCharm 3. 终端执行: s ...