PAT甲级——A1025 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 (≤), 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

简单的排序题,使用结构体
 1 #include <iostream>
 2 #include <vector>
 3 #include <string>
 4 #include <algorithm>
 5 using namespace std;
 6 struct Node
 7 {
 8     string No;
 9     int score, final_rank, location_num, local_rank;
10 };
11
12 bool cmp(Node* a, Node* b)
13 {
14     return (a->score == b->score) ? (a->No < b->No) : (a->score > b->score);
15 }
16 int N, K;
17 vector<Node*>allPerson;
18 int main()
19 {
20     cin >> N;
21     for (int i = 1; i <= N; ++i)
22     {
23         cin >> K;
24         vector<Node*>temp;
25         for (int j = 0; j < K; ++j)
26         {
27             Node* node = new Node;
28             cin >> node->No >> node->score;
29             node->location_num = i;
30             temp.push_back(node);
31         }
32         sort(temp.begin(), temp.end(), cmp);
33         for (int j = 0; j < temp.size(); ++j)
34         {
35             if (j > 0 && temp[j]->score == temp[j - 1]->score)
36                 temp[j]->local_rank = temp[j - 1]->local_rank;
37             else
38                 temp[j]->local_rank = j + 1;
39         }
40         allPerson.insert(allPerson.end(), temp.begin(), temp.end());
41     }
42     sort(allPerson.begin(), allPerson.end(), cmp);
43     cout << allPerson.size() << endl;
44     for (int j = 0; j < allPerson.size(); ++j)
45     {
46         if (j>0 && allPerson[j]->score == allPerson[j - 1]->score)
47             allPerson[j]->final_rank = allPerson[j - 1]->final_rank;
48         else
49             allPerson[j]->final_rank = j + 1;
50         cout << allPerson[j]->No << " " << allPerson[j]->final_rank << " " <<
51             allPerson[j]->location_num << " " << allPerson[j]->local_rank << endl;
52     }
53     return 0;
54 }

原文地址:https://www.cnblogs.com/zzw1024/p/11216185.html

时间: 2024-08-30 16:34:49

PAT甲级——A1025 PAT Ranking的相关文章

PAT 甲级1025 PAT Ranking (25 分)(结构体排序,第一次超时了,一次sort即可小技巧优化)

题意: 给定一次PAT测试的成绩,要求输出考生的编号,总排名,考场编号以及考场排名. 分析: 题意很简单嘛,一开始上来就,一组组输入,一组组排序并记录组内排名,然后再来个总排序并算总排名,结果发现最后一个测试点超时. 发现自己一开始太傻太盲目,其实只要一次性全部输进来,记录好考场编号,一次排序就可以了.既然只排了一次,怎么计算考场排名呢,这里我用了三个数组 int g_rank[100];//记录各个考场当前排到的名次 (当前最后一个人的名次) int g_score[100];//记录个考场当

PAT 甲级 A1025 (2019/02/17)

#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn = 30010; struct Student{ char id[15]; int score; int local_number; int local_rank; }stu[maxn]; bool cmp(Student a, Student b){ if(a.score != b.sco

PAT甲级1005 Spell It Right

题目:PAT甲级 1005 题解:水题.看到题目的第一时间就在想一位一位的mod,最后一加一转换就完事了.结果看到了N最大为10的100的次方,吓得我赶紧放弃这个想法... 发现碰到这种情况用字符串十分好用,这道题应该考察的就是这一点.大致思路就是把数字的每一位放到字符串中,然后通过ASCII码得到每一位的相加结果num,然后把num一位一位的放到stack中,使用stack是因为它先进先出的特性,最后输出就行了. 代码: 1 #include<cstdio> 2 #include<qu

PAT甲级考前整理

终于在考前,刷完PAT甲级130道题目,不容易!!!每天沉迷在刷题之中而不能超脱,也是一种境界.PAT甲级题目总的说卡题目的比较多,卡测试点的比较少,有些题目还会有题意混淆,这点就不吐槽了吧.静下心来耍这130道题,其实磨练的是一种态度与手感,养成的是一种习惯.热爱AC没有错!! 130道题目主要的考点: 1.排序:快速排序,直接插入排序,希尔排序,分治排序,堆排序. 2.图论:拓扑排序.最短路径.深度搜索.广度搜索. 3.树:树的遍历.完全二叉树.AVL. 4.其他:并查集,模拟,哈希.背包.

PAT甲级考试题库1001 A+B Format 代码实现及相关知识学习

准备参加九年九月份的PAT甲级证书考试,对网站上的题目进行总结分析: 1001题 A+B Format (20 分) Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits). 计算a+b的值并以一定格式输出其和sum(数字需要

PAT甲级专题|最短路

PAT甲级最短路 主要算法:dijkstra 求最短最长路.dfs图论搜索. 1018,dijkstra记录路径 + dfs搜索路径最值 25分,错误点暂时找不出.. 如果只用dijkstra没法做,只能得20分 #include<bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 510; int cmax,n,ter,m; int caps[maxn]; int g[maxn][m

【PAT甲级】1070 Mooncake (25 分)(贪心水中水)

题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全部出手的利润.输出最大利润. trick: 测试点2可能包含M不为整数的数据.(尽管题面说明M是正整数,可是根据从前PAT甲级题目的经验,有可能不是整数.....) 代码: #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using names

静态PAT、动态PAT实验报告

网络运维 静态PAT.动态PAT 实验报告姓名: 李军 班级: NTD1710 日期: 2017 年 1 月 5 日实验任务 配置要求:PC192.168.1.1通过防火墙动态PAT转换访问PC120.1.1.1Server通过防火墙静态PAT转换访问PC120.1.1.1思路及实验步骤 配置思路:第一步.首先配置终端设备PC机和Server服务器的IP地址第二步.配置SW3.ISP.R1设备的VLAN及IP,使其能够ping 通终端PC机IPSW3:port link-type accessp

1141 PAT Ranking of Institutions PAT甲级

After each PAT, the PAT Center will announce the ranking of institutions based on their students’ performances. Now you are asked to generate the ranklist.Input Specification:Each input file contains one test case. For each case, the first line gives