题意:排序题。

思路:通过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. coredata 数据库升级

    在真实开发中,因为需求是不断变化的,说不定什么时候就需要往模型里添加新的字段,添加新的模型,甚至是大规模的重构:所以数据的迁移就显得尤为重要了. CoreData 中,数据迁移本质就是把旧的 SQLi ...

  2. Android中获取资源的id和url方法总结

    一,获取android工程里面的各种资源的id; 1.1 string型 比如下面: << string name=”OK”>> 客户端请求成功 << / stri ...

  3. jenkins的Master/Slave模式

    一. Master/Slave模式 分担jenkins服务器的压力,任务分配到其它执行机来执行 Master:Jenkins服务器 Slave:执行机(奴隶机).执行Master分配的任务,并返回任务 ...

  4. Autolayout .Compact or .Regular [iPhone/iPad]

  5. a标签设置锚点定位div

    <a href="#5F">锚点5</a> </br></br></br></br></br>& ...

  6. forEach和map的区别

    写法上没什么区别,只是返回值会不一样,map能够返回每一项,而forEach则返回undefined,以后要用哪个你知道了吧?map返回新的数组,可以进行后续更多的操作,例如: let arr = [ ...

  7. 剑指Offer(第二版)面试案例:树中两个节点的最低公共祖先节点

    (尊重劳动成果,转载请注明出处:http://blog.csdn.net/qq_25827845/article/details/74612786冷血之心的博客) 剑指Offer(第二版)面试案例:树 ...

  8. ajax函数里不能用this调用

    ajax函数里不能用this调用,想用的话,在ajax外面弄个变量var mythis = $(this),然后在里面用就行了 因为,在ajax方法里写$(this)指向的是最近调用它的jquery对 ...

  9. jQuery attr 与 prop 区别最简单分析

    比较经典的解释: 在处理html元素本身就带有的固有属性时,使用prop方法,对于html元素中,我们自己定义的dom属性时,使用attr方法. 而咱自己的理解是: attr会忠实的获取设置dom标签 ...

  10. (三)js循环结构

    1.循环结构 a)    当循环 语法:while(condition){         code...     }     do(){         code...     } while(); ...