PAT_A1141#PAT Ranking of Institutions
#
Source:
PAT A1141 PAT Ranking of Institutions (25 分)
Description:
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 andT
the top level;Score
is an integer in [0, 100]; andSchool
is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed thatID
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 ofScoreB/1.5 + ScoreA + ScoreT*1.5
, whereScoreX
is the total score of the testees belong to this institution on levelX
; andNs
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 ofNs
. 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
Keys:
- map(C++ STL)
- string(C++ STL)
- 快乐模拟
Attention:
- 字符串转换为小写:transform(s.begin(),s.end(),s.begin(),::tolower);
- 字符串转换为大写:transform(s.begin(),s.end(),s.begin(),::toupper);
Code:
1 /*
2 Data: 2019-05-24 09:43:26
3 Problem: PAT_A1141#PAT Ranking of Institutions
4 AC: 33:40
5
6 题目大意:
7 按分数排名
8 输入:
9 第一行给出,考试人数N<=1e5
10 接下来N行给出,ID(1位字母+5位数字),分数[0,100],学校(<=6,大小写敏感)
11 输出:
12 第一行输出,学校总数M
13 接下来M行,排名(>=1), 学校(小写),总分(B/1.5+A+T*1.5),考生数
14 排序规则,总分递减,人数递增,学校字典序
15 */
16
17 #include<cstdio>
18 #include<iostream>
19 #include<algorithm>
20 #include<map>
21 #include<string>
22 using namespace std;
23 const int M=1e5+10;
24 int pt=1;
25 struct node
26 {
27 string id;
28 double score;
29 int num;
30 }info[M];
31 map<string,int> mp;
32
33 int ToInt(string s)
34 {
35 if(mp[s]==0)
36 {
37 mp[s]=pt;
38 info[pt].num=0;
39 info[pt].score=0;
40 info[pt].id=s;
41 return pt++;
42 }
43 else
44 return mp[s];
45 }
46
47 bool cmp(node a, node b)
48 {
49 if((int)a.score != (int)b.score)
50 return a.score > b.score;
51 else if(a.num != b.num)
52 return a.num < b.num;
53 else
54 return a.id < b.id;
55 }
56
57 int main()
58 {
59 #ifdef ONLINE_JUDGE
60 #else
61 freopen("Test.txt", "r", stdin);
62 #endif
63
64 int n;
65 scanf("%d", &n);
66 for(int i=0; i<n; i++)
67 {
68 string id,stu;
69 double score;
70 cin >> id >> score >> stu;
71 transform(stu.begin(),stu.end(),stu.begin(),::tolower);
72 int sch = ToInt(stu);
73 if(id[0]=='T')
74 score*=1.5;
75 else if(id[0]=='B')
76 score/=1.5;
77 info[sch].score += score;
78 info[sch].num++;
79 }
80 sort(info+1,info+pt,cmp);
81 printf("%d\n", pt-1);
82 int r=1;
83 for(int i=1; i<pt; i++)
84 {
85 if(i==1 || (int)info[i].score!=(int)info[i-1].score)
86 r=i;
87 cout<<r<<' '<<info[i].id<<' '<<(int)info[i].score<<' '<<info[i].num<<endl;
88 }
89
90 return 0;
91 }
转载于//www.cnblogs.com/blue-lin/p/10916684.html
还没有评论,来说两句吧...