1137 Final Grading

题目描述
知识点: STL、排序
思路: 简单按照题目意思计算成绩并排序输出就好了。注意:比较总分的时候由于是根据四舍五入之后排序的,所以在比较前需要用round函数进行四舍五入后进行比较。

#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<math.h>
using namespace std;
const int N = 1e5+10;
struct S{
    string id;
    int ass;
    int mid,fin;
    double fing;
    bool operator < (const S s) const{
        int x = round(fing);
        int y = round(s.fing);
        if(x != y) return x > y;
        return id < s.id;
    }
}s[N];
int main(){
    int n,m,k;
    unordered_map<string,S> map;
    cin>>n>>m>>k;
    while(n--){
        string id;
        int ass;
        cin>>id>>ass;
        if(map.count(id))
            map[id].ass = ass;
        else map[id] = {id,ass,-1,-1};
    }
    while(m--){
        string id;
        int mid;
        cin>>id>>mid;
        if(map.count(id))
            map[id].mid = mid;
        else map[id] = {id,0,mid,-1};
    }
    while(k--){
        string id;
        int fin;
        cin>>id>>fin;
        if(map.count(id))
            map[id].fin = fin;
        else map[id] = {id,-1,-1,fin};
    }  
    int cnt = 0;
    for(auto i : map){
        auto ss = i.second;
        if(ss.ass < 200) continue;
        double fing = ss.fin;
        if(ss.mid > ss.fin) fing = (double)ss.mid * 0.4 + (double)ss.fin * 0.6;
        if(round(fing) < 60) continue;
        ss.fing = fing;
        s[cnt++] = ss;
    }
    sort(s,s+cnt);
    for(int i = 0;i < cnt;i++){
        cout<<s[i].id<<" "<<s[i].ass<<" "<<s[i].mid<<" "<<s[i].fin<<" ";
        printf("%.0lf\n",s[i].fing);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值