zoukankan      html  css  js  c++  java
  • 排序5 PAT Judge

    题目:https://pintia.cn/problem-sets/1268384564738605056/problems/1291317697694580737
    题解:https://www.liuchuo.net/archives/2260
    代码:

    #include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    struct node {
        int rank, id, total = 0;
        vector<int> score;
        int passnum = 0;
        bool isshown = false;
    };
    bool cmp1(node a, node b) {
        if(a.total != b.total)
            return a.total > b.total;
        else if(a.passnum != b.passnum)
            return a.passnum > b.passnum;
        else
            return a.id < b.id;
    }
    
    int main() {
        int n, k, m, id, num, score;
        scanf("%d %d %d", &n, &k, &m);
        vector<node> v(n + 1);
        for(int i = 1; i <= n; i++)
            v[i].score.resize(k + 1, -1);
        vector<int> full(k + 1);
        for(int i = 1; i <= k; i++)
            scanf("%d", &full[i]);
        for(int i = 0; i < m; i++) {
            scanf("%d %d %d", &id, &num, &score);
            v[id].id = id;
            v[id].score[num] = max(v[id].score[num], score);
            if(score != -1)
                v[id].isshown = true;
            else if(v[id].score[num] == -1)
                v[id].score[num] = -2;
        }
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= k; j++) {
                if(v[i].score[j] != -1 && v[i].score[j] != -2)
                    v[i].total += v[i].score[j];
                if(v[i].score[j] == full[j])
                    v[i].passnum++;
            }
        }
        sort(v.begin() + 1, v.end(), cmp1);
        for(int i = 1; i <= n; i++) {
            v[i].rank = i;
            if(i != 1 && v[i].total == v[i - 1].total)
                v[i].rank = v[i - 1].rank;
        }
        for(int i = 1; i <= n; i++) {
            if(v[i].isshown == true) {
                printf("%d %05d %d", v[i].rank, v[i].id, v[i].total);
                for(int j = 1; j <= k; j++) {
                    if(v[i].score[j] != -1 && v[i].score[j] != -2)
                        printf(" %d", v[i].score[j]);
                    else if(v[i].score[j] == -1)
                        printf(" -");
                    else
                        printf(" 0");
                }
                printf("
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    web前端网站收藏
    wordpress安装(ubuntu+nginx+php+mariadb)
    硬盘分区表知识——详解硬盘MBR
    useradd添加用户
    闭包closure this
    什么是同步加载与异步加载
    css 两个span标签在同一行,高度不一样
    CSS label之间存在间距
    JS中如何跳出循环/结束遍历
    el-checkbox-group 无法选中
  • 原文地址:https://www.cnblogs.com/simon-chou/p/13620122.html
Copyright © 2011-2022 走看看