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
题⽬⼤意:
给出每个学⽣的id、分数、学校,学校名称不区分⼤⼩写,输出学校排名、学校名称、总
加权成绩、学校参赛⼈数。学校名称输出时候以⼩写⽅式输出。
分析
先将校名转换成小写,然后用stoifun和map将校名映射成整形,然后根据id计算总分数,在跟据score>cnt>school优先顺序排序,最后处理排名。
注意:
总分数取整数部分是要对最后的总和取整数部分,不能每次都直接⽤int存储,不然会有⼀
个3分测试点不通过,对于这题如果有5个元素就排序5个,如果将其他空元素也加入排序会影响最终的结果
//1141 PAT Ranking of Institutions (25分)
#include <bits/stdc++.h>
using namespace std;
struct res
{
string school;
int cnt;
double score;
int rank;
};
map<string,int> stoint;
int id=0;
int stoifun(string str)
{
if(stoint[str]==0)
{
id++;
stoint[str]=id;
return id;
}
else
return stoint[str];
}
bool cmp(res r1,res r2)
{
if((int)r1.score!=(int)r2.score)
return (int)r1.score>(int)r2.score;
else if(r1.cnt!=r2.cnt)
return r1.cnt<r2.cnt;
else
return r1.school<r2.school;
}
int main()
{
int n;
cin>>n;
vector<res> v(n+1);
for(int i=0; i<n; i++)
{
string id,school;
double score;
cin>>id;
scanf("%lf",&score);
cin>>school;
for(int j=0; j<school.size(); j++)
school[j]=tolower(school[j]);
int temp=stoifun(school);
if(id[0]=='T')
{
score=score*1.5;
}
else if(id[0]=='B')
{
score=score/1.5;
}
v[temp].school=school;
v[temp].cnt++;
v[temp].score+=score;
}
sort(v.begin()+1,v.begin()+1+id,cmp);
v[1].rank=1;
for(int i=2; i<=id; i++)
{
v[i].rank=i;
if((int)v[i].score==(int)v[i-1].score)
v[i].rank=v[i-1].rank;
}
cout<<id<<endl;
for(int i=1; i<=id; i++)
{
cout<<v[i].rank<<" "<<v[i].school<<" "<<(int)v[i].score<<" "<<v[i].cnt<<endl;
}
return 0;
}
DayDream_x
发布了21 篇原创文章 · 获赞 1 · 访问量 383
私信
关注