zoukankan      html  css  js  c++  java
  • 1025 PAT Ranking (25)

    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


    题目大意:给出各个考点的考生id和成绩,要求把所有考点的信心合在一起,输出考生的id,合并后的排名, 考场位置, 合并前的排名
    思路:建立一个struct node保存每一个学生的id, 最终排名,局部排名,成绩以及考场。 每录入完一个考场的信息,就对其排序确定学生的局部排名。 待所有信心录入完成后,对所有的考生排名,确定名次
    注意点:用long long保存id否则会溢出
     1 #include<iostream>
     2 #include<algorithm>
     3 #include<vector>
     4 #include<string>
     5 using namespace std;
     6 struct node{
     7   long long id;//用long long保存 防止溢出
     8   int score, final, location, local;
     9 };
    10 
    11 bool cmp(node a, node b){
    12   if(a.score!=b.score)return a.score>b.score;
    13   return a.id < b.id;
    14 }
    15 
    16 int main(){
    17   int n, k, i, j, sum=0;
    18   scanf("%d", &n);
    19   vector<node> v;
    20   for(i=1; i<=n; i++){
    21     scanf("%d", &k);
    22     sum += k;
    23     node stu;
    24     stu.location=i;
    25     for(j=0; j<k; j++){
    26       scanf("%ld %d", &stu.id, &stu.score);
    27       v.push_back(stu);
    28     }
    29     //对该考场的学生进行排序
    30     sort(v.begin()+sum-k, v.begin()+sum, cmp);
    31     v[sum-k].local=1;
    32     for(j=1; j<k; j++){//确定每个考场中的名次
    33       if(v[sum-k+j].score==v[sum-k+j-1].score) v[sum-k+j].local=v[sum-k+j-1].local;
    34       else v[sum-k+j].local=j+1;
    35     }
    36     
    37   }
    38   sort(v.begin(), v.end(), cmp); //对所有考生进行排序
    39     v[0].final = 1;
    40     printf("%d
    %013ld %d %d %d
    ", v.size(), v[0].id,  v[0].final, v[0].location, v[0].local);
    41     for(i=1; i<v.size(); i++){//确定名次,并输出结果
    42       if(v[i].score==v[i-1].score) v[i].final = v[i-1].final;
    43       else v[i].final = i+1;
    44       printf("%013ld %d %d %d
    ",  v[i].id,  v[i].final, v[i].location, v[i].local);
    45     }
    46   return 0;
    47 }
    有疑惑或者更好的解决方法的朋友,可以联系我,大家一起探讨。qq:1546431565
  • 相关阅读:
    使用网络服务
    Linux Socket 学习(九)
    Linux Socket学习(六)
    Linux Socket学习(八)
    Developing Software in Visual Studio .NET with NonAdministrative Privileges
    html5+css3实现一款注册表单
    linux编程下signal()函数
    深入理解Oracle索引(10):索引列字符类型统计信息的32位限制
    智能手机屏幕清晰度用户体现的分析:PPI与PPI2
    架设邮件服务器windows 2003 POP3服务,SMTP服务收发邮件
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9161679.html
Copyright © 2011-2022 走看看