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.
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
结尾无空行
如果你运行出来,只拿了 22 分,而且 是测试点五错误,那么这篇文章应该能解决你的问题,原因出在 ScoreB/1.5 + ScoreA + ScoreT*1.5
这里,如果你定义的是 int 类型,就可能出现错误,因为题目中说的是 which is defined to be the integer part of
这个数字的整数部分,举个例子,如果三个人的 B 级分数是 2,除以 1.5 如果是 int 类型,结果是 三个 1 相加,但是如果是 double 类型,就会变成 3 个 1.333 相加,也就是 4
分析了一下,其实就是 把 int 改成 double 就好啦
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<cctype>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<cstring>
using namespace std;
int n;
const int N = 100001;
struct Node {
string sch_name;
double total_weight;
int stu_count;
} a[100001], b[100001];
bool cmp(Node x, Node y) {
if (x.total_weight == y.total_weight) {
if (x.stu_count == y.stu_count) {
return x.sch_name < y.sch_name;
}
return x.stu_count < y.stu_count;
}
return x.total_weight > y.total_weight;
}
unordered_map<string, Node> mp;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
string id, sch_name;
double score;
cin >> id >> score >> sch_name;
for (int j = 0; j < sch_name.size(); j++) {
sch_name[j] = tolower(sch_name[j]);
}
mp[sch_name].sch_name = sch_name;
if (id[0] == 'A') {
score = score;
} else if (id[0] == 'T') {
score *= 1.5;
} else {
score /= 1.5;
}
mp[sch_name].total_weight += score;
mp[sch_name].stu_count++;
}
int i = 0;
for (auto it = mp.begin(); it != mp.end(); it++) {
it->second.total_weight = (int) it->second.total_weight;
b[i++] = it->second;
}
sort(b, b + i, cmp);
int t = 1;
cout << i << endl;
cout << t << " " << b[0].sch_name << " " << b[0].total_weight << " " <<
b[0].stu_count << endl;
for (int j = 1; j < i; j++) {
if (b[j].total_weight == b[j - 1].total_weight) {
cout << t << " " << b[j].sch_name << " " << b[j].total_weight << " " <<
b[j].stu_count << endl;
} else {
t = j + 1;
cout << t << " " << b[j].sch_name << " " << b[j].total_weight << " " <<
b[j].stu_count << endl;
}
}
return 0;
}