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.
翻译:每个输入文件包含一个测试用例。对于每种情况,第一行包含一个正数N(≤100),即测试位置的数量。接着是N个排名表,每一个都以一个包含正整数K(≤300)的行开始,K行包含被测者的注册号(13位数字)和每个被测者的总分。一行中的所有数字都用空格隔开。
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.
翻译:对于每个测试用例,首先在一行中打印测试的总数。然后按以下格式打印最终格式:
registration_number final_rank location_number local_rank
位置的编号从1到N。输出必须按最终列组的不降序排序。分数相同的被测者必须具有相同的排名,并且输出必须按其账号的不降序排序。
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 3会出错,发现应该要当分数不同按照分数从小到大排序,当分数相同时,要按照准考证号从小到大排序
- 学生id用string类型存储,防止出现0000001这种学号,要输出前导0
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
struct stu
{
string id;
int score;
int location;
int local_rank;
};
void get_localrank(vector<stu>&);
bool cmp(stu a, stu b)
{
if (a.score != b.score)
return a.score > b.score;
else
return a.id < b.id;
}
int main()
{
int n, total = 0;
cin >> n;
vector<stu> all;
for (int i = 0; i < n; i++)
{
int k;
vector<stu> loc;
cin >> k;
total += k;
for (int j = 0; j < k; j++)
{
stu s;
cin >> s.id >> s.score;
s.location = i + 1;
loc.push_back(s);
}
get_localrank(loc); //进行当前考点的排名
for (int i = 0; i < loc.size(); i++)
all.push_back(loc[i]); //放入存储全部考点学生的数组
}
sort(all.begin(), all.end(), cmp); //对全部学生进行排序
int rank = 1;
cout << total << endl;
for (int i = 0; i < all.size(); i++)
{
if (i > 0 && all[i].score != all[i - 1].score)
rank = i + 1;
cout << all[i].id << ' ' << rank << ' ' << all[i].location << ' ' << all[i].local_rank << endl;
}
system("pause");
return 0;
}
void get_localrank(vector<stu>& local)
{
sort(local.begin(), local.end(), cmp);
local[0].local_rank = 1;
for (int i = 1; i < local.size(); i++)
{
if (local[i].score == local[i - 1].score)
local[i].local_rank = local[i - 1].local_rank;
else
local[i].local_rank = i + 1;
}
}
本文介绍了一个程序设计能力测试(PAT)的排名合并问题。通过结构体存储考生信息,并实现每个考点内的排名,最后对所有考生进行总排名。文章提供了完整的代码实现。
548

被折叠的 条评论
为什么被折叠?



