1025. PAT Ranking (25)

来源:互联网 发布:p2p网贷数据库设计 编辑:程序博客网 时间:2024/06/05 19:37

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:
251234567890001 951234567890005 1001234567890003 951234567890002 771234567890004 8541234567890013 651234567890011 251234567890014 1001234567890012 85
Sample Output:
91234567890005 1 1 11234567890014 1 2 11234567890001 3 1 21234567890003 3 1 21234567890004 5 1 41234567890012 5 2 21234567890002 7 1 51234567890013 8 2 31234567890011 9 2 4

题意,给定n个人,求他们的按各种规则的排序

题解:结构体排序,sort随便搞搞就好了,注意,学号会有前导零,一定要输出出来.



#include <cstdio>#include <cstring>#include <algorithm>#include <vector>using namespace std;typedef long long LL;struct node{    LL id;    int score, final_rank, lct, local_rank;    bool operator<(const node & X) const{        if (score == X.score) return id < X.id;        return score > X.score;    }};int main() {    int n, k;    scanf("%d", &n);    vector<node> v;    for (int i = 1; i <= n; ++i) {        scanf("%d", &k);        vector<node> t;        for (int j = 0; j < k; ++j) {            node tmp;            tmp.lct = i;            scanf("%lld%d", &tmp.id, &tmp.score);            t.push_back(tmp);        }        sort(t.begin(), t.end());        t[0].local_rank = 1;        for (int j = 1; j < k; ++j) {            if (t[j].score == t[j - 1].score)                t[j].local_rank = t[j - 1].local_rank;            else                t[j].local_rank = j + 1;        }        v.insert(v.end(), t.begin(), t.end());    }    sort(v.begin(), v.end());    v[0].final_rank = 1;    for (int i = 1; i < v.size(); ++i) {        if (v[i].score == v[i - 1].score)            v[i].final_rank = v[i - 1].final_rank;        else            v[i].final_rank = i + 1;    }    printf("%ld\n", v.size());    int cnt = v[0].final_rank = 1;    for (int i = 0; i < v.size(); ++i)        printf("%013lld %d %d %d\n", v[i].id, v[i].final_rank, v[i].lct, v[i].local_rank);    return 0;}


0 0