1012. The Best Rank (25)
2015-11-14 21:04
369 查看
1012. The Best Rank (25)
时间限制400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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
提交代码
http://www.patest.cn/contests/pat-a-practise/1012
#include <cstdio> #include <cmath> #include <iostream> #include <cstring> #include <string> #include <vector> #include <algorithm> #include <map> using namespace std; #define N 101 struct stu { int no ; int c , m , e , a ; int rank_c , rank_m , rank_e , rank_a ; }; bool cmp1(stu s1,stu s2) { return s1.c > s2.c ; } bool cmp2(stu s1,stu s2) { return s1.m > s2.m ; } bool cmp3(stu s1 , stu s2) { return s1.e > s2.e ; } bool cmp4(stu s1 , stu s2) { return s1.a > s2.a ; } int n , m ; vector<stu> vt; map<int , int> mp ; int main() { //freopen("in.txt" , "r" , stdin) ; while( scanf("%d%d" , &n , &m) != EOF) { vt.clear() ; mp.clear() ; stu st ; int i ; for(i =0 ; i < n ; i++) { scanf("%d%d%d%d" , &st.no ,&st.c , &st.m , &st.e); /* 求平均数注意是四舍五入 (这个是根据自己提交的错误 , 再对比题目例子数据检查出来的), 所以要善于根据错误判断自己的程序什么地方没做好 */ st.a = st.c + st.m + st.e ; if(st.a % 3 <= 1) { st.a = st.a / 3 ; }else{ st.a = st.a / 3 + 1 ; } vt.push_back(st) ; } // c sort(vt.begin() , vt.end() , cmp1); vt[0].rank_c = 1 ; for(i = 1 ; i < n ; i++) { if(vt[i].c == vt[i-1].c ) vt[i].rank_c = vt[i-1].rank_c ; else vt[i].rank_c = i + 1 ; } // m sort(vt.begin() , vt.end() , cmp2); vt[0].rank_m = 1 ; for(i = 1 ; i < n ; i++) { if(vt[i].m == vt[i-1].a ) vt[i].rank_m = vt[i-1].rank_m ; else vt[i].rank_m = i + 1 ; } // e sort(vt.begin() , vt.end() , cmp3); vt[0].rank_e = 1 ; for(i = 1 ; i < n ; i++) { if(vt[i].e == vt[i-1].c ) vt[i].rank_e = vt[i-1].rank_e; else vt[i].rank_e = i + 1 ; } // a sort(vt.begin() , vt.end() , cmp4); vt[0].rank_a = 1 ; mp[vt[0].no] = 1 ; for(i = 1 ; i < n ; i++) { mp[vt[i].no] = i + 1; if(vt[i].a == vt[i-1].a ) vt[i].rank_a = vt[i-1].rank_a ; else vt[i].rank_a = i + 1 ; } int tmpNo ; for(i = 0 ; i < m ; i++) { scanf("%d" , &tmpNo) ; if(mp[tmpNo] == 0) printf("N/A\n"); else{ stu nStu = vt[mp[tmpNo] - 1] ; int bestRank = nStu.rank_a ; char c = 'A' ; if(nStu.rank_c < bestRank) { bestRank = nStu.rank_c ; c = 'C' ; } if(nStu.rank_m < bestRank) { bestRank = nStu.rank_m ; c = 'M' ; } if(nStu.rank_e < bestRank) { bestRank = nStu.rank_e ; c = 'E' ; } printf("%d %c\n" , bestRank , c) ; } }// for } return 0 ; }
相关文章推荐
- jquery实现密码和确认密码的输入框中不能复制,粘贴,剪切,和右键
- shell中的tee命令的使用
- CodeForces 111B - Petya and Divisors
- hdu 4791 Alice's Print Service(贪心)
- Mac上MySQL忘记root密码且没有权限的处理办法&workbench的一些tips
- 面向对象编程的思考
- 本机win7, 虚拟机ubuntu文件共享debug
- 日经春秋 20151114
- SDUT OJ 数据结构实验之二叉树二:遍历二叉树
- vc6.0工程升级到vs2013multibyte字符集加_T()宏快捷方法
- getParameter和getAttribute的区别是什么?
- 【Linux下安装配置】锐捷客户端安装
- 现在可以确定增量压缩的类型了
- 冒泡排序原理及实现
- 安装SQL Server 2012遇到“需要更新的以前的Visual Studio 2010实例.”
- Java 反射机制
- 软件工程线上课程(C语言实践篇)学习心得总结
- 2013 ACM/ICPC Asia Regional Changsha Online Contest C
- android图片压缩问题
- Java异常处理 编程 考试成绩 优良中差判断