题意:排序题。

思路:通过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. resultType没有指定就会报错

    报错如下: 改正方式就是添加resultType. org.apache.ibatis.executor.ExecutorException: A query was run and no Resul ...

  2. shell 数组操作

    1. 定义数组: var_array=(one two three four five) 2.常用操作 获取数组长度: ${#var_array[@]} 获取所有数组元素:  ${var_array[ ...

  3. 【Python】循环设计

    转载:作者:Vamei 出处:http://www.cnblogs.com/vamei range() 在Python中,for循环后的in跟随一个序列的话,循环每次使用的序列元素,而不是序列的下标. ...

  4. python递归 及 面向对象初识及编程思想

    递归 及 面向对象初识及编程思想   一.递归 1.定义: 在函数内部,可以调用其他函数.如果一个函数在内部调用自身本身,这个函数就是递归函数. (1)递归就是在过程或函数里调用自身: (2)在使用递 ...

  5. OC-通知+Block

    =================================== 一.通知(NSNotification) NSNotification 通知类,这个类中有 NSNotificationCent ...

  6. JavaScript: Where to Insert JavaScript and output

    1.Javescript in <head> <!DOCTYPE html> <html> <head> <script> function ...

  7. jQuery对象[0]倒底是什么?

    s[0]倒底是什么?(s为jQuery对象)代码:var s=$("div"); alert(s.length);alert(s[0]); jQuery对象默认都有个0索引,s为j ...

  8. 打包发布自己的nodejs包

    下午的时候写了一篇关于一个不成熟的模板引擎的博客,觉得还是不太够,然后就封装了起来,做成了一款开发包.最后为了尝试一下如何发布自己的包,就又完善了一下.做此文以记之. 初衷 说来也不是什么高大上的东西 ...

  9. 类Flask实现前后端交互之代码聊天室

    前言 框架 项目目录及各自功能 流程图 后端 server backend exector 前端 ajax 页面更新 演示 简易应答模式 代理模式处理外部请求 后台日志 总结 前言 这两天老是做梦,全 ...

  10. LINUX (centos)设置IP地址,网关,DNS

    首先:备份原始配置文件: [logonmy@logon ~]$ cd /etc/sysconfig/network-scripts/ [logon@logon network-scripts]$ pw ...