题解 | 排名

#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
using namespace std;

struct stP {
    string id;
    int score;
    stP(string id, int score): id(id), score(score) {}
    bool operator<(stP b){
        if(score==b.score)return id<b.id;
        else return score>b.score;
    }
};

int main() {
    int n, m, g;
    while (cin >> n) {
        if (n == 0)break;
        cin >> m >> g;
        int score[m];
        for (int i = 0; i < m; i++)cin >> score[i];
        vector<stP>a;
        while (n--) {
            string id;
            int k;
            cin >> id >> k;
            int ap = 0;
            while (k--) {
                int y;
                cin >> y;
                ap += score[y-1];
            }
            bool pass = false;
            if (ap >= g)a.push_back(stP(id, ap));
        }
        sort(a.begin(), a.end());
        cout<<a.size()<<endl;
        for(auto x:a){
            cout<<x.id<<" "<<x.score<<endl;
        }
    }
}

难度在于复杂的输入函数,其他的就非常简单的,唯一的要求就是输出及格的,我这里为了方便就只存了及格的,然后要求同分数按照序号排序,这个直接利用string比较方法即可

全部评论

相关推荐

不愿透露姓名的神秘牛友
01-19 22:44
已编辑
中机六院 智能工厂机械工艺设计 年包7左右 本科其他
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务