zoukankan      html  css  js  c++  java
  • PAT 甲级 1025 1025 PAT Ranking

    https://pintia.cn/problem-sets/994805342720868352/problems/994805474338127872

    Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.

    Input Specification:

    Each input file contains one test case. For each case, the first line contains a positive number N (≤), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.

    Output Specification:

    For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:

    registration_number final_rank location_number local_rank
    

    The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.

    Sample Input:

    2
    5
    1234567890001 95
    1234567890005 100
    1234567890003 95
    1234567890002 77
    1234567890004 85
    4
    1234567890013 65
    1234567890011 25
    1234567890014 100
    1234567890012 85
    

    Sample Output:

    9
    1234567890005 1 1 1
    1234567890014 1 2 1
    1234567890001 3 1 2
    1234567890003 3 1 2
    1234567890004 5 1 4
    1234567890012 5 2 2
    1234567890002 7 1 5
    1234567890013 8 2 3
    1234567890011 9 2 4

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    int T;
    int r[30010];
    int sum = 0;
    
    struct Node{
        char id[20];
        int score;
        int FR;
        int LN;
        int LR;
    }node[30010];
    
    bool cmp1(const Node& a, const Node& b) {
        if(a.score != b.score)
            return a.score > b.score;
        return strcmp(a.id, b.id) < 0;
    }
    
    
    int main() {
        scanf("%d", &T);
        for(int t = 1; t <= T; t ++) {
            scanf("%d", &r[t]);
            for(int i = 1; i <= r[t]; i ++) {
                sum ++;
                scanf("%s%d", node[sum].id, &node[sum].score);
                node[sum].LN = t;
            }
            sort(node + sum - r[t] + 1, node + sum + 1, cmp1);
    
            //for(int i = sum - r[t] + 1; i <= sum; i ++)
              //  printf("%s
    ", node[i].id);
            //printf("%d     %d
    ", sum - r[t] + 1, sum);
    
            node[sum - r[t] + 1].LR = 1;
            for(int i = sum - r[t] + 2; i <= sum + 1; i ++) {
                if(node[i].score == node[i - 1].score)
                    node[i].LR = node[i - 1].LR;
                else
                    node[i].LR = i - (sum - r[t]);
            }
            //for(int i = sum - r[t] + 1; i <= sum + 1; i ++)
            //printf("%s  %d
    ", node[i].id, node[i].LR);
        }
        sort(node + 1, node + 1 + sum, cmp1);
        node[1].FR = 1;
        for(int i = 2; i <= sum; i ++) {
            if(node[i].score == node[i - 1].score)
                node[i].FR = node[i - 1].FR;
            else
                node[i].FR = i;
        }
    
        printf("%d
    ", sum);
        for(int i = 1; i <= sum; i ++) {
            printf("%s %d %d %d
    ", node[i].id, node[i].FR, node[i].LN, node[i].LR);
        }
        return 0;
    }
    

      

  • 相关阅读:
    -1%256的值是多少?
    Glut,程序的基本架构
    剑指offer:数值的整数次方
    剑指offer:二进制中1的个数
    剑指offer:斐波那契数列的应用
    剑指offer:斐波那契数列
    剑指offer:旋转数组中的最小数字
    弱智的grub消除法
    POJ 3126 Prime Path
    HDU 1426 Sudoku Killer
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/9841852.html
Copyright © 2011-2022 走看看