PAT(Advanced lecel) 1012. The Best Rank
来源:互联网 发布:乐视网络电视手机版 编辑:程序博客网 时间:2024/05/20 01:11
原题链接:http://pat.zju.edu.cn/contests/pat-a-practise/1012
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
//代码粗糙,还望勿喷
#include <stdio.h>#include <vector>#include <algorithm>using namespace std;struct STU{ int id; int grades[4];//分别为A,C,M,E 为避免误差,用总分来代替平均分};struct StuRank{ int id; int rank; char c;};const int INF = 0x7FFFFFFF;char ch[4] = {'A', 'C', 'M', 'E'};bool sortByA(STU stu1, STU stu2){ return stu1.grades[0]>stu2.grades[0];}bool sortByC(STU stu1, STU stu2){ return stu1.grades[1]>stu2.grades[1];}bool sortByM(STU stu1, STU stu2){ return stu1.grades[2]>stu2.grades[2];}bool sortByE(STU stu1, STU stu2){ return stu1.grades[3]>stu2.grades[3];}void RankByGrade(int n, int m, int idx,vector<STU> &stuVec, vector<StuRank> &ranklist){ if(idx == 0) { sort(stuVec.begin(), stuVec.end(), sortByA); } else if(idx == 1) { sort(stuVec.begin(), stuVec.end(), sortByC); } else if(idx == 2) { sort(stuVec.begin(), stuVec.end(), sortByM); } else { sort(stuVec.begin(), stuVec.end(), sortByE); } int rank = 1;//需要考虑并列排名的情况 for(int i=0; i<n; ++i) { if(i>0 && stuVec[i].grades[idx] != stuVec[i-1].grades[idx]) { rank = i+1; } for(int j=0; j<m; ++j) { if(ranklist[j].id == stuVec[i].id && ranklist[j].rank>rank) { ranklist[j].rank = rank; ranklist[j].c = ch[idx]; break; } }//end inner for }//end outer for}int main(){ int n,m; vector<STU> stuVec; vector<StuRank> rankList; scanf("%d %d", &n, &m); stuVec.reserve(n); rankList.reserve(m); STU stu; for(int i=0; i<n; ++i) { scanf("%d %d %d %d", &stu.id, &stu.grades[1], &stu.grades[2], &stu.grades[3]); stu.grades[0] = stu.grades[1]+stu.grades[2]+stu.grades[3]; stuVec.push_back(stu); } StuRank sturank; for(int i=0; i<m; ++i) { scanf("%d", &sturank.id); sturank.rank = INF; rankList.push_back(sturank); } for(int i=0; i<4; ++i) { RankByGrade(n, m, i, stuVec, rankList); } for(int i=0; i<m; ++i) { if(rankList[i].rank != INF) { printf("%d %c\n", rankList[i].rank, rankList[i].c); } else { printf("N/A\n"); } } return 0;}
- PAT(Advanced lecel) 1012. The Best Rank
- 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 (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 解题文档
- 浙大 PAT Advanced level 1012. The Best Rank
- 【PAT】【Advanced Level】1012. The Best Rank (25)
- PAT (Advanced Level) Practise 1012. The Best Rank (25)
- PAT 1012. The Best Rank
- PAT 1012. The Best Rank
- 【PAT】1012. The Best Rank
- 浙大PAT (Advanced Level) Practise 1012 The Best Rank (25)
- Pat(Advanced Level)Practice--1012(The Best Rank)
- PAT (Advanced Level) Practise 1012 The Best Rank (25)
- PAT (Advanced Level) Practise 1012 The Best Rank
- OC 文件路径获取和操作
- 最长起伏子序列
- Android学习笔记(1.2)Fragment
- xcode5.1下安装ios5.0模拟器
- linux C编程入门之静态链接库、动态链接库的编译与链接
- PAT(Advanced lecel) 1012. The Best Rank
- Eclipse插件安装的三种方法
- 遞迴touch
- Struts的安装
- POJ训练计划2485_Highways(最小生成树)
- jQuery基础教程(第四版)
- 奇怪的问题——来源:古老的智力题
- Tanimoto相似度与Bregman距离
- KMP算法C++实现