PAT甲级——A1141 PATRankingofInstitution
阅读原文时间:2023年07月09日阅读:2

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 (≤), 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
#include
#include
#include
#include
using namespace std;
struct Node
{
string id, school;
double tws;//切记,一定是double,每次PAT就是在这里下套
int score, nums, rank;
};
int main()
{
int n;
cin >> n;
vectorv(n);
unordered_map>map;//记录相同学校的是哪些人
for (int i = ; i < n; ++i) { string name, school; int score; cin >> name >> score >> school;
for (int j = ; j < school.size(); ++j) school[j] = tolower(school[j]); v[i] = { name,school,0.0,score,, }; map[school].push_back(i); } vectorres;
for (auto ptr = map.begin(); ptr != map.end(); ++ptr)
{
vectorp = ptr->second;
res.push_back({ "", v[p[]].school, 0.0, , (int)p.size(), });//将相同学校的分数相加
for (auto a : p)
{
if (v[a].id[] == 'A')
res.back().tws += v[a].score;
else if (v[a].id[] == 'B')
res.back().tws += v[a].score / 1.5;
else
res.back().tws += v[a].score * 1.5;
}
}
sort(res.begin(), res.end(), [](Node a, Node b) {//排名
if ((int(a.tws)) == (int(b.tws)) && a.nums == b.nums)
return a.school < b.school; else if ((int(a.tws)) == (int(b.tws))) return a.nums < b.nums; else return a.tws > b.tws;
});
cout << res.size() << endl; for (int i = ; i < res.size(); ++i) { if (i > && ((int)res[i].tws) == ((int)res[i-].tws))
res[i].rank = res[i - ].rank;
else
res[i].rank = i + ;
cout << res[i].rank << " " << res[i].school << " " << (int)res[i].tws << " " << res[i].nums << endl;
}
return ;
}

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章