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 a positive integer N (≤105), which is the number of testees. Then N lines follow, each gives the information of a testee in the following format:
ID Score School
where ID is a string of 6 characters with the first one representing the test level: B stands for the basic level, A the advanced level and T the top level; Score is an integer in [0, 100]; and School is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed that ID is unique for each testee.
Output Specification:
For each case, first print in a line the total number of institutions. Then output the ranklist of institutions in nondecreasing order of their ranks in the following format:
Rank School TWS Ns
where Rank is the rank (start from 1) of the institution; School is the institution code (all in lower case); ; TWS is the total weighted score which is defined to be the integer part of ScoreB/1.5 + ScoreA + ScoreT*1.5, where ScoreX is the total score of the testees belong to this institution on level X; and Ns is the total number of testees who belong to this institution.
The institutions are ranked according to their TWS. If there is a tie, the institutions are supposed to have the same rank, and they shall be printed in ascending order of Ns. If there is still a tie, they shall be printed in alphabetical order of their codes.
Sample Input:
10
A57908 85 Au
B57908 54 LanX
A37487 60 au
T28374 67 CMU
T32486 24 hypu
A66734 92 cmu
B76378 71 AU
A47780 45 lanx
A72809 100 pku
A03274 45 hypu
Sample Output:
5
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2
#include<iostream>
#include<vector>
#include<cstring>
#include<unordered_map>
#include<algorithm>
using namespace std;
struct school
{
int score;
int test_cnt;
string school;
};
bool cmp(school a, school b){
if(a.score != b.score){
return a.score > b.score;
}else if (a.test_cnt != b.test_cnt)
{
return a.test_cnt < b.test_cnt;
}else
{
return a.school < b.school;
}
}
int main(){
int n;
cin >> n;
// vector<testees> v(n);
unordered_map<string, double> socre;
unordered_map<string, int> nct;
for(int i = 0; i < n; i++){
string temp_id;
double temp_score;
string temp_school;
cin >> temp_id >> temp_score >> temp_school;
// scanf("%s %d %s", temp_id, &temp_score, &temp_school[0]);
// v.push_back(temp);
double fin_score = 0;
if(temp_id[0] == 'B'){
fin_score = temp_score / 1.5;
}
if(temp_id[0] == 'A'){
fin_score = temp_score;
}
if(temp_id[0] == 'T'){
fin_score = temp_score * 1.5;
}
transform(temp_school.begin(), temp_school.end(), temp_school.begin(), ::tolower);
socre[temp_school] += fin_score;
nct[temp_school]++;
}
vector<school> out_result;
for(auto it : socre){
school temp_school;
temp_school.score = int(it.second);
temp_school.school = it.first;
temp_school.test_cnt = nct[it.first];
out_result.push_back(temp_school);
}
cout << out_result.size() << endl;
sort(out_result.begin(), out_result.end(), cmp);
int temp_s = out_result[0].score;
int rank = 1;
printf("%d %s %d %d\n", rank, out_result[0].school.c_str(), out_result[0].score, out_result[0].test_cnt);
for(int i = 1; i < out_result.size(); i++){
if(temp_s == out_result[i].score)
printf("%d %s %d %d\n", rank, out_result[i].school.c_str(), out_result[i].score, out_result[i].test_cnt);
else
{
rank = i + 1;
printf("%d %s %d %d\n", rank, out_result[i].school.c_str(), out_result[i].score, out_result[i].test_cnt);
}
temp_s = out_result[i].score;
}
return 0;
}
本文介绍了一个基于学生表现的PAT考试排名系统的实现细节。系统接收考试成绩输入,包括考生ID、分数和所属机构,并生成按总加权分数排序的机构排名列表。排名依据机构的总加权分数,相同分数下按考生数量和机构代码字母顺序排列。
365

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



