L2-027 名人堂与代金券

作者: smatrcHendsa | 来源:发表于2019-03-17 15:43 被阅读0次

    这种排序题竟然没写出来 血亏 比赛的时候脑子一抽用map去了
    老是不知道怎么写比较器怎么破
    https://pintia.cn/problem-sets/994805046380707840/problems/994805055176163328

    #include <stdio.h>
    #include <iostream>
    #include <cstring>
    #include <vector>
    #include <queue>
    #include <map>
    #include <set>
    #include <sstream>
    #include <algorithm>
    using namespace std;
    int N, G, K;
    const int si = 10007;
    struct Node {
        int v;
        string s;
    };
    bool cmp (Node x, Node y){
        if (x.v != y.v) return x.v > y.v;
        return x.s < y.s;
    };
    Node no[si];
    int cnt = 0;
    
    int main() {
        cin >> N >> G >> K;
        int sum = 0;
        for (int i = 0; i < N; i++) {
            string str; int a;
            cin >> str >> a;
            if (a >= G) {
                sum += 50;
            }
            if (a >= 60 && a < G) {
                sum += 20;
            }
            no[cnt].v = a;
            no[cnt++].s = str;
        }
        
        cout << sum << endl;
        sort(no, no + cnt, cmp);
        int num = 0;
        while (num < K) {
            int tp = 0;
            while(no[num + tp].v == no[num + tp + 1].v) {
                printf("%d ", num + 1);
                cout << no[num + tp].s;
                printf(" %d\n", no[num + tp].v);
                tp++;
            }
            printf("%d ", num + 1);
            cout << no[num + tp].s;
            printf(" %d\n", no[num + tp].v);
            num += tp + 1;
        }
        return 0;
    }
    

    相关文章

      网友评论

        本文标题:L2-027 名人堂与代金券

        本文链接:https://www.haomeiwen.com/subject/qveumqtx.html