zoukankan      html  css  js  c++  java
  • PAT1025:PAT Ranking

    1025. PAT Ranking (25)

    时间限制
    200 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    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 (<=100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (<=300), 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

    思路
    给出Pat不同考场的考生成绩,最后按总的成绩排名输出他们的相关信息。格式为:【准考证号】 【总排名】 【所在考场】 【考场排名】 。
    主要是排序问题。
    1.先处理区域排名,按成绩从高到低排名,成绩相同的按号码从低到高来排序(但是它们的排名还是相同的)。比如 1230001 成绩为99,1230002成绩为99,1230003成绩为60.那么1230001和1230002并列第1名,而1230003则为第3名。
    2.将区域排名的数组里面的成绩插入到总排名的数组中,如此循环。
    3.按照2中处理区域排名的方式处理总排名。
    4.循环输出总排名信息就行。

    代码
    #include<iostream>
    #include<vector>
    #include<algorithm>
    /*
    0.用一个新vector存放最终rank排名的所有学生
    1.输入
    2.根据区域学生的成绩排序来决定区域排名。
    3.处理相同分数排名并将结果插入到最终排名的vector中
    4.最终排名排序
    5.处理相同分数排名
    6.输出
    */
    using namespace std;
    class student
    {
    public:
        long long id;
        int grade;
        int finalrank;
        int location;
        int localrank;
    };
    
    bool cmp(const student& a,const student& b)
    {
        if(a.grade != b.grade)
            return a.grade > b.grade;
        else
            return a.id < b.id;
    }
    
    int main()
    {
        int n;
        vector<student> finalres;
        while(cin >> n)
        {
          for(int i = 0;i < n;i++)
          {
              int k;
              cin >> k;
              vector<student> loc(k);
              for(int j = 0;j < k;j++)
              {
                  cin >> loc[j].id >> loc[j].grade;
                  loc[j].location = i + 1;
              }
              sort(loc.begin(),loc.end(),cmp);
              loc[0].localrank = 1;
              finalres.push_back(loc[0]);
              for(int j = 1;j < k;j++)
              {
                 loc[j].localrank = (loc[j].grade == loc[j - 1].grade)? loc[j - 1].localrank:j + 1;
                 finalres.push_back(loc[j]);
              }
          }
          sort(finalres.begin(),finalres.end(),cmp);
          cout << finalres.size() << endl;
          finalres[0].finalrank = 1;
          printf("%013lld %d %d %d
    ",finalres[0].id,finalres[0].finalrank,finalres[0].location,finalres[0].localrank);  //注意格式化输出13位id
          for(int i = 1;i < finalres.size();i++)
          {
              finalres[i].finalrank = (finalres[i].grade == finalres[i - 1].grade) ? finalres[i - 1].finalrank:i + 1;
              printf("%013lld %d %d %d
    ",finalres[i].id,finalres[i].finalrank,finalres[i].location,finalres[i].localrank);  //注意格式化输出13位id
              //cout << finalres[i].id << " " << finalres[i].finalrank << " "
              //<< finalres[i].location << " " << finalres[i].localrank << endl;
          }
    
        }
    }
    
    
    

      

     
  • 相关阅读:
    m个苹果放入n个篮子
    C++ sort函数用法 C中的qsort
    C常见机试题
    二维数组作为函数参数的几种方法
    远程调用相关技术
    反射 与 序列化
    MFC 三种消息
    【2019.09.13】中秋快乐!来点福大猫咪色图ヽ(=^・ω・^=)丿
    【2019.09.11】用交互式思维导图展示学期规划(软件工程实践2019第二次作业)
    【2019.09.07】审视自我~(软件工程实践2019第一次作业)
  • 原文地址:https://www.cnblogs.com/0kk470/p/7910743.html
Copyright © 2011-2022 走看看