PAT甲级 1012
来源:互联网 发布:淘宝出售京东e卡 编辑:程序博客网 时间:2024/06/16 15:48
The Best Rank
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 A
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 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 Input
5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999
Sample Output
1 C
1 M
1 E
1 A
3 A
N/A
考点
- sort的用法
题解
- 用sort得到4个分数的总体排名
- 用if判断语句,找到4个排名中最靠前的一个。如果有相同的,则根据题目给的优先级来做。[我根据优先级来做if判断,故不需要再判断是否有相同的rank。]
#include <algorithm>#include <stdio.h>#include <string.h>using namespace std;#define MAXSIZE (2000+10)int maps[1000000+10];int query[MAXSIZE];struct node{ int score[4]; int id;}stu[MAXSIZE];int ranks[MAXSIZE][4];int idx;bool cmp(node a,node b){ return a.score[idx]>b.score[idx];}int main(){ //freopen("./in","r",stdin); memset(maps,-1,sizeof(maps)); int n,ms; int id,c,m,e; int i,j; scanf("%d %d",&n,&ms); for(i=0;i<n;i++){ scanf("%d %d %d %d",&id,&c,&m,&e); stu[i].id=i; stu[i].score[0]=c+m+e; stu[i].score[1]=c; stu[i].score[2]=m; stu[i].score[3]=e; maps[id]=i; } for(i=0;i<ms;i++)scanf("%d",query+i); int r,cnt; for(i=0;i<4;i++){ idx=i,r=1,j=0; sort(stu,stu+n,cmp); while(j<n){ ranks[stu[j].id][i]=r; j++; cnt=1; while(j<n && stu[j].score[i]==stu[j-1].score[i]){ ranks[stu[j].id][i]=r; cnt++; j++; } r+=cnt; } } char rank_order[4]={'A','C','M','E'}; for(i=0;i<ms;i++){ idx=maps[query[i]]; if(idx==-1){ printf("N/A\n"); continue; } r=ranks[idx][0]; j=0; if(r>ranks[idx][1]){ j=1; r=ranks[idx][1]; } if(r>ranks[idx][2]){ j=2; r=ranks[idx][2]; } if(r>ranks[idx][3]){ j=3; r=ranks[idx][3]; } printf("%d %c\n",r,rank_order[j]); } return 0;}
- PAT(甲级)1012
- PAT甲级1012
- PAT甲级1012
- PAT甲级 1012
- 浙大PAT甲级-1012
- PAT 甲级
- 牛客网 PAT(甲级) 1012Kuchiguse (20)
- PAT 1012(甲级) The Best Rank
- pat甲级1012-The Best Rank
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1008
- PAT(甲级)1009
- 子集和
- Android消息处理机制
- win7笔记本创建WiFi热点
- 机器学习实战--决策树分类
- 慕课网学习spring入门篇-专题一 IOC
- PAT甲级 1012
- SpringMVC之组合注解@GetMapping
- Android(Java)字符、字符串的查询、检索、截取、合并等操作
- Ubuntu下配置make3.8.1
- Windows学习(009)--线程(三)线程同步
- Sqlite数据库存储数据
- 我配置的 Oh my zsh
- leetcode 64. Minimum Path Sum
- Linux下GDB调试