关闭

PAT(A-LEVEL) 1025 PAT Ranking

68人阅读 评论(0) 收藏 举报

1025 PAT Ranking

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


排序题,不算太难。
关键在于掌握sort()函数的第三个参数的使用方法。
形如:

bool cmp(Student a, Student b)
{
    if(a.score !=b.score) return a.score > b.score;
    else return strcmp(a.name,b.name) < 0;
}

注意:

  • sort函数头文件为algorithm

#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAX 300000
using namespace std;

struct Student{
    char id[15];
    int score;
    int location;
    int local_rank;
};
Student testee[MAX+10];

bool cmp(Student,Student);

int main() 
{   
    int N,K;
    int count=0;        //total testees number 
    scanf("%d",&N); 
    for(int i=1;i<=N;i++){
        scanf("%d",&K);
        //input id & score of the testees in (i)'s test location
        for(int j=0;j<K;j++){
            scanf("%s%d",testee[count].id,&testee[count].score);
            testee[count].location=i;
            count++;
        }

        //sort the (i)'s test location
        sort(testee+count-K,testee+count,cmp);
        //local ranking
        int rank=1,temp=2;
        testee[count - K].local_rank=rank; 
        for( int j = count - K + 1 ; j < count ; j++ ){
            if ( testee[j].score < testee[j-1].score ) rank=temp;  
            testee[j].local_rank=rank;
            temp++;
        }
    }

    printf("%d\n",count);
    //final ranking
    sort(testee,testee+count,cmp);
    int final_rank=1; 
    printf("%s %d %d %d\n",testee[0].id,final_rank,testee[0].location,testee[0].local_rank);
    for(int i=1;i<count;i++){
        if(testee[i].score<testee[i-1].score) final_rank=i+1;
        printf("%s %d %d %d\n",testee[i].id,final_rank,testee[i].location,testee[i].local_rank);
    }
    return 0;
}

bool cmp(Student x,Student y)
{
    if ( x.score != y.score ) return x.score > y.score;
    else return strcmp(x.id,y.id) < 0;
}
0
0
查看评论

【PAT1025】PAT Ranking

1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programming Ability Test (PAT) is...
  • tiantangrenjian
  • tiantangrenjian
  • 2013-11-28 22:00
  • 1929

PAT 1025 PAT Ranking(双重排序)

题目https://www.patest.cn/contests/pat-a-practise/1025 题意:给出每个考场中每个学生的成绩,求所有学生的总排名以及所在考场内的分排名。注意,同分的学生排名相同,其后的学生排名后推。 解题思路简单的排序题,用结构体保存每个学生的所有信息。先对分数局...
  • lecholin
  • lecholin
  • 2017-06-16 19:48
  • 224

1025. PAT Ranking (25) PAT 甲级

Problem Description Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test ...
  • SY_Yu
  • SY_Yu
  • 2016-07-19 00:16
  • 319

PAT_乙级 1025 反转链表

1.题目描述: 给定一个常数K以及一个单链表L,请编写程序将L中每K个结点反转。例如:给定L为1→2→3→4→5→6,K为3,则输出应该为3→2→1→6→5→4;如果K为4,则输出应该为4→3→2→1→5→6,即最后不到K个元素不反转。 输入格式: 每个输入包含1个测试用例。每个测试用例第1行...
  • prim_learn
  • prim_learn
  • 2016-12-05 19:32
  • 740

PAT乙级—1025. 反转链表 (25)-native

给定一个常数K以及一个单链表L,请编写程序将L中每K个结点反转。例如:给定L为1→2→3→4→5→6,K为3,则输出应该为3→2→1→6→5→4;如果K为4,则输出应该为4→3→2→1→5→6,即最后不到K个元素不反转。输入格式:每个输入包含1个测试用例。每个测试用例第1行给出第1个结点的地址、结点...
  • wanmeiwushang
  • wanmeiwushang
  • 2016-06-10 22:18
  • 1288

pat 1025 PAT Ranking

简单题,只是一开始用vector rank[NUM]用得不太熟,巩固了一下sort的compare函数写法。得抓紧时间做题了,以后博客先略写,有空再来补充。 #include #include #include #include using namespace std; struct st...
  • jjike
  • jjike
  • 2013-03-02 20:34
  • 291

PAT 1025. PAT Ranking

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1025 题解: 先分别排序,再整体排序。 代码: #include #include #include #include #include #include #include #include #in...
  • ACM_Ted
  • ACM_Ted
  • 2014-02-28 15:15
  • 617

【PAT】1025. PAT Ranking (25)

题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1025 题目描述: Programming Ability Test (PAT) is organized by the College of Computer Science and Tec...
  • realxuejin
  • realxuejin
  • 2013-08-27 15:37
  • 1099

PAT 1025. 反转链表 (25)

给定一个常数K以及一个单链表L,请编写程序将L中每K个结点反转。例如:给定L为1→2→3→4→5→6,K为3,则输出应该为3→2→1→6→5→4;如果K为4,则输出应该为4→3→2→1→5→6,即最后不到K个元素不反转。 输入格式: 每个输入包含1个测试用例。每个测试用例第1行给出第1个...
  • gemire
  • gemire
  • 2014-03-08 10:21
  • 4971

PAT 甲级 1025 PAT Ranking

PAT 甲级 1025 PAT Ranking
  • Dacc123
  • Dacc123
  • 2016-05-31 08:19
  • 332
    个人资料
    • 访问:1667次
    • 积分:127
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:2篇
    • 译文:2篇
    • 评论:0条