1080 MOOC期终成绩 (25 分)

pat题目链接

题目链接

我的思路

用map存储数据,然后转存到vector使用自定义sort排序,最后输出。但是过不了最后一个测试点。百思不得其解。

我的代码

#include <iostream>
#include <map>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;
struct Node {
    int midSore{-1}, finalSore{-1}, testSore{-1}, sore{0};
};

bool comp(const pair<string, Node> &n1, const pair<string, Node> &n2) {
    if (n1.second.sore != n2.second.sore) {
        return n1.second.sore > n2.second.sore;
    } else {
        return n1.first < n2.first;
    }
}

map<string, Node> Data, Pass;

int main() {
    int p, m, n;
    cin >> p >> m >> n;
    while (p--) {
        string s;
        int d;
        cin >> s >> d;
        if (d <= 900)
            Data[s].testSore = d;
    }
    while (m--) {
        string s;
        int d;
        cin >> s >> d;
        if (d >= 0 && d <= 100)
            Data[s].midSore = d;
    }
    while (n--) {
        string s;
        int d;
        cin >> s >> d;
        if (d >= 0 && d <= 100)
            Data[s].finalSore = d;
    }
    for (auto &x:Data)
        if (x.second.testSore >= 200) {
            if (x.second.midSore > x.second.finalSore) {
                if (x.second.midSore * 0.4 + x.second.finalSore * 0.6 >= 60) {
                    x.second.sore = lround(x.second.midSore * 0.4 + x.second.finalSore * 0.6);
                    Pass.emplace(x);
                }
            } else if (x.second.finalSore >= 60) {
                x.second.sore = x.second.finalSore;
                Pass.emplace(x);
            }
        }
    vector<pair<string, Node>> vec(Pass.begin(), Pass.end());
    sort(vec.begin(), vec.end(), comp);
    for (const auto &x:vec)
        cout << x.first << " " << x.second.testSore << " " << x.second.midSore << " " <<
             x.second.finalSore << " " << x.second.sore << endl;
    return 0;
}

提交结果

提交结果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值