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 (≤10^5
), 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.
注意点:
使用map可能超时
score是取整数部分,而不是四舍五入
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<string>
#include<vector>
using namespace std;
struct ins{
string school;
float score = 0;
int num = 0;
};
unordered_map<string, ins>rec;
int n;
bool cmp(ins s1, ins s2) {
int i1 = s1.score, i2 = s2.score;
if (i1 != i2)return i1 > i2;
if (s1.num != s2.num)return s1.num < s2.num;
else
return s1.school < s2.school;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
string id, sch;
float score;
cin >> id >> score >> sch;
transform(sch.begin(), sch.end(), sch.begin(), ::tolower);
if (id[0] == 'B')score /= 1.5;
else if (id[0] == 'T')score *= 1.5;
rec[sch].school = sch;
rec[sch].num++;
rec[sch].score += score;
}
vector<ins>temp;
for (auto it = rec.begin(); it != rec.end(); it++)temp.push_back(it->second);
sort(temp.begin(), temp.end(), cmp);
int ts0 = temp[0].score, rank = 1;
cout << temp.size() << endl;
for (int i = 0; i < temp.size(); i++) {
int tsi = temp[i].score;
if (tsi != ts0) {
rank = i + 1;
ts0 = tsi;
}
cout << rank << " " << temp[i].school << " " << tsi << " " << temp[i].num << endl;
}
return 0;
}