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
排序题,题目貌似卡了一个精度,一开始存分数的时候就是直接int存,这样会有测试点过不了
后面再排序之前加了一个精度转换就好了。
1 #include <bits/stdc++.h> 2 using namespace std; 3 int n; 4 struct Node 5 { 6 string s; 7 double val; 8 string name; 9 friend bool operator < (const Node &a, const Node &b){ 10 return a.name < b.name; 11 } 12 }node[100005]; 13 struct Lode 14 { 15 string st; 16 double val; 17 int shu; 18 friend bool operator < (const Lode &a, const Lode &b){ 19 if(a.val == b.val){ 20 if(a.shu == b.shu){ 21 return a.st< b.st; 22 } 23 return a.shu < b.shu; 24 } 25 return a.val > b.val; 26 } 27 }lode[100005]; 28 string lower_(string s){ 29 for(int i = 0; i < s.length(); i++) 30 s[i] = tolower(s[i]); 31 return s; 32 } 33 int main(){ 34 ios::sync_with_stdio(false); 35 cin.tie(0); 36 cout.tie(0); 37 cin >> n; 38 for(int i = 0; i < n; i++){ 39 cin >>node[i].s>>node[i].val>>node[i].name; 40 node[i].name = lower_(node[i].name); 41 } 42 sort(node,node+n); 43 int pos = 0; 44 string na = node[0].name; 45 double sum = 0; 46 int ci = 0; 47 for(int i = 0; i < n; i++){ 48 if(node[i].name == na){ 49 ci++; 50 if(node[i].s[0] == 'A'){ 51 sum = sum + node[i].val; 52 }else if(node[i].s[0] == 'B'){ 53 sum = sum + (double)(node[i].val/1.5); 54 }else{ 55 sum = sum + (double)(node[i].val*1.5); 56 } 57 }else{ 58 lode[pos++] = {na,sum,ci}; 59 na = node[i].name; 60 sum = 0; 61 ci = 0; 62 i--; 63 } 64 } 65 lode[pos++] = {na,sum,ci}; 66 for(int i = 0; i < pos; i++) 67 lode[i].val = (int)lode[i].val; 68 sort(lode,lode+pos); 69 int cnt = 1; 70 cout <<pos<<endl; 71 for(int i = 0 ; i < pos; i++){ 72 if(i == 0 || ((int)lode[i].val == (int)lode[i-1].val)) 73 cout << cnt <<" "; 74 else{ 75 cout << i+1 << " "; 76 cnt = i+1; 77 } 78 cout << lode[i].st<<" "<<(int)lode[i].val<<" "<<lode[i].shu<<endl; 79 } 80 81 return 0; 82 }