题解 | 分数线划定

分数线划定

https://www.nowcoder.com/practice/2395fa7b6c6e452e8d8310a7cfdbe902

#include <cmath>
#include <iostream>
#include <iterator>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;


int main() {
    int a,m;
    cin >> a>> m;
    int t = std::floor(1.5 * m);
    vector<map<string,string>> s;
    for(int i =0;i<a;i++){
        map<string,string> m;
        string value1;
        string value2;
        cin >> value1 >> value2;
        m["id"] = value1;
        m["score"] = value2;
        s.push_back(m);
    }

    sort(s.begin(),s.end(),[](const map<string,string>& a,const map<string,string>& b){
        int scoreA = stoi(a.at("score"));
        int scoreB = stoi(b.at("score"));
        if(scoreA != scoreB){
            return scoreA > scoreB;
        }else{
            return a.at("id")  < b.at("id");
        }
    });
    string interview_score = t>a? s[s.size()-1].at("score") :s[t-1].at("score");
    vector<map<string,string>> filtered;
    copy_if(s.begin(),s.end(),back_inserter(filtered),[&](const auto& item){
        return stoi(item.at("score")) >= stoi(interview_score);
    });

    cout << interview_score << " " << filtered.size() << endl;
    for(const auto& e :filtered){
        cout << e.at("id") << " " << e.at("score") << endl;
    }

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

牛牛不会牛泪:脉脉太多这种了,纯水军
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务