1141 PAT Ranking of Institutions
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.
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.
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.
- 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
- 5
- 1 cmu 192 2
- 1 au 192 3
- 3 pku 100 1
- 4 hypu 81 2
- 4 lanx 81 2
总结:这道题目好久之前在乙级也写过了,需要注意的就是最后总成绩的计算是先将所有的浮点成绩算出来,然后通过 int 取整,可以先用map
代码:
- #include
- #include
- #include
- #include
- #include
- using namespace std;
-
- struct node{
- string id;
- int tws,ns;
- };
- bool cmp(node a,node b){
- if(a.tws!=b.tws) return a.tws>b.tws;
- else if(a.ns!=b.ns) return a.ns
- else return a.id
- }
- int main(){
- int n;
- scanf("%d",&n);
- map
int> m; - vector
v(n+2) ; -
- string id,school;
- int index=1;
- for(int i=0;i
- string t;
- double s;
- cin >> id;
- scanf("%lf",&s);
- if(id[0]=='B') s/=1.5;
- else if(id[0]=='T') s*=1.5;
- cin >> school;
- for(char c:school) t+=tolower(c);
- if(!m[t]) m[t]=index++;
- v[m[t]].id=t;
- v[m[t]].tws+=s;
- v[m[t]].ns++;
- }
- sort(v.begin()+1,v.begin()+index,cmp);
- printf("%d\n",index-1);
- int rank=0,pre=-1;
- for(int i=1;i
- if(pre!=v[i].tws) rank=i;
- printf("%d ",rank);
- cout << v[i].id;
- printf(" %d %d\n",v[i].tws,v[i].ns);
- pre=v[i].tws;
- }
-
- return 0;
- }
柳神代码:
- #include
- #include
- #include
- #include
- #include
- using namespace std;
-
- struct node{
- string id;
- int tws,ns;
- };
- bool cmp(node a,node b){
- if(a.tws!=b.tws) return a.tws>b.tws;
- else if(a.ns!=b.ns) return a.ns
- else return a.id
- }
- int main(){
- int n;
- scanf("%d",&n);
- unordered_map
int> cnt; - unordered_map
double> score; -
- for(int i=0;i
- string id,school,t;
- double s;
- cin >> id;
- scanf("%lf",&s);
- if(id[0]=='B') s/=1.5;
- else if(id[0]=='T') s*=1.5;
- cin >> school;
- for(char c:school) t+=tolower(c);
- score[t]+=s;
- cnt[t]++;
- }
- vector
ans; - for(auto it=score.begin();it!=score.end();it++)
- ans.push_back({it->first,it->second,cnt[it->first]});
- sort(ans.begin(),ans.end(),cmp);
- printf("%d\n",ans.size());
- int rank=0,pre=-1;
- for(int i=0;i
size();i++){ - if(pre!=ans[i].tws) rank=i+1;
- printf("%d ",rank);
- cout << ans[i].id;
- printf(" %d %d\n",ans[i].tws,ans[i].ns);
- pre=ans[i].tws;
- }
-
- return 0;
- }
好好学习,天天向上!
我要考研!
-
相关阅读:
pytorch tensor的广播机制
Linux的资源和限制
day15_集合
使用【时间差】调整时间datetime.timedelta()
Linux系统编程(四)——signal信号处理
C++:map和set容器
从编写操作系统的角度看上下文切换
深入浅出理解CSS中的3D变换:踏上立体视觉之旅
如何让 Llama2、通义千问开源大语言模型快速跑在函数计算上?
python selenium控制浏览器打开网页 模拟鼠标动作
-
原文地址:https://blog.csdn.net/weixin_50679551/article/details/127601195