【PAT】【Advanced Level】1012. The Best Rank (25)
来源:互联网 发布:淘宝挂钩 编辑:程序博客网 时间:2024/05/17 18:42
1012. The Best Rank (25)
To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algebra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks -- that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.
For example, The grades of C, M, E and A - Average of 4 students are given as the following:
StudentID C M E A310101 98 85 88 90310102 70 95 88 84310103 82 87 94 88310104 91 91 91 91
Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.
Input
Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (<=2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.
Output
For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.
The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.
If a student is not on the grading list, simply output "N/A".
Sample Input5 6310101 98 85 88310102 70 95 88310103 82 87 94310104 91 91 91310105 85 90 90310101310102310103310104310105999999Sample Output
1 C1 M1 E1 A3 AN/A
原题链接:
https://www.patest.cn/contests/pat-a-practise/1012
思路:
结构体排序
按照不同的关键字,编写不同的cmp函数,然后调用sort排序,统计。
坑点:
并列的情况
CODE:
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<string>#include<map>#include<cmath>using namespace std;typedef struct S{ string name; int gra[3]; int aver; int ran[4];};map<string,int> ma;char op[4]={'A','C','M','E'};S stu[2001];bool cmp0(S a,S b){ return a.aver>b.aver;}bool cmp1(S a,S b){ return a.gra[0]>b.gra[0];}bool cmp2(S a,S b){ return a.gra[1]>b.gra[1];}bool cmp3(S a,S b){ return a.gra[2]>b.gra[2];}int main(){ int m,n; cin>>n>>m; for (int i=0;i<n;i++) { cin>>stu[i].name>>stu[i].gra[0]>>stu[i].gra[1]>>stu[i].gra[2]; stu[i].aver=floor((stu[i].gra[0]+stu[i].gra[1]+stu[i].gra[2])/3); } sort(stu,stu+n,cmp0); for (int i=0;i<n;i++) { if (i==0) stu[i].ran[0]=1; if (i!=0) { if (stu[i].aver!=stu[i-1].aver) stu[i].ran[0]=i+1; else stu[i].ran[0]=stu[i-1].ran[0]; } } sort(stu,stu+n,cmp1); for (int i=0;i<n;i++) { if (i==0) stu[i].ran[1]=1; if (i!=0) { if (stu[i].gra[0]!=stu[i-1].gra[0]) stu[i].ran[1]=i+1; else stu[i].ran[1]=stu[i-1].ran[1]; } } sort(stu,stu+n,cmp2); for (int i=0;i<n;i++) { if (i==0) stu[i].ran[2]=1; if (i!=0) { if (stu[i].gra[1]!=stu[i-1].gra[1]) stu[i].ran[2]=i+1; else stu[i].ran[2]=stu[i-1].ran[2]; } } sort(stu,stu+n,cmp3); for (int i=0;i<n;i++) { if (i==0) stu[i].ran[3]=1; if (i!=0) { if (stu[i].gra[1]!=stu[i-1].gra[1]) stu[i].ran[3]=i+1; else stu[i].ran[3]=stu[i-1].ran[3]; } } for (int i=0;i<n;i++) ma[stu[i].name]=i+1; for (int i=0;i<m;i++) { string t; cin>>t; if (ma[t]==0) { cout<<"N/A"<<endl; continue; } int maa=10000; int ind=-1; for (int j=3;j>=0;j--) { if (stu[ma[t]-1].ran[j]<=maa) { maa=stu[ma[t]-1].ran[j]; ind=j; } } cout<<maa<<" "<<op[ind]<<endl; } return 0;}
- 【PAT Advanced Level】1012. The Best Rank (25)
- 【c++】PAT (Advanced Level)1012. The Best Rank (25)*
- PAT (Advanced Level) Practise 1012. The Best Rank (25)
- 【PAT】【Advanced Level】1012. The Best Rank (25)
- PAT (Advanced Level) Practise 1012. The Best Rank (25)
- PAT (Advanced) 1012. The Best Rank (25)
- PAT (Advanced) 1012. The Best Rank (25)
- 1012. The Best Rank @ PAT (Advanced Level) Practise
- [PAT (Advanced Level) ]1012. The Best Rank 解题文档
- 浙大 PAT Advanced level 1012. The Best Rank
- 浙大PAT (Advanced Level) Practise 1012 The Best Rank (25)
- PAT (Advanced Level) Practise 1012 The Best Rank (25)
- 1012. The Best Rank (25)——PAT (Advanced Level) Practise
- PAT (Advanced Level) 1012. The Best Rank (25) 最佳排名,结构体排序,哈希查询
- PAT(Advanced lecel) 1012. The Best Rank
- Pat(Advanced Level)Practice--1012(The Best Rank)
- PAT (Advanced Level) Practise 1012 The Best Rank
- PAT-PAT (Advanced Level) Practise 1012 The Best Rank (25) (简单模拟)【二星级】
- 洛谷P1200 [USACO1.1]你的飞碟在这儿Your Ride Is He…
- MySQL的Query Cache原理分析
- 人人都看得懂的正则表达式
- Mysql报错:communications link failure
- Ubuntu添加root用户和登录界面
- 【PAT】【Advanced Level】1012. The Best Rank (25)
- 线性表(顺序表)之C++封装
- 在Android studio中用网格布局做计算机界面
- ubuntu安装
- How to enable IOMMU in Fedora
- Android控件 如何把控
- CSS选择器
- Java Io流总结
- Angular2 学习