【PAT】1012. The Best Rank (25)
题目链接: 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 Algrbra), 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
分析:
(1)考察对结构体的排序。
(2)注意处理成绩相同的情况,如 1 1 3 4, 因为有两个人并列第一,所以第二名实际是排在第三的位置。
代码来自于:http://blog.csdn.net/sunbaigui/article/details/8656832#reply
- #include<iostream>
- #include<vector>
- #include<set>
- #include<map>
- #include<queue>
- #include<algorithm>
- #include<string>
- #include<string.h>
- using namespace std;
- int n;//student
- int m;//query
- typedef struct Node
- {
- string name;
- int grade[4];
- int bestRank;
- int bestGrade;
- }Node;
- typedef struct SortNode
- {
- int g, idx, rank;
- bool operator>(const SortNode& orh)const
- {
- return g>orh.g;
- }
- }SortNode;
- char CharTable[4]={'A','C','M','E'};
- #define INF 0x6FFFFFFF
- int main()
- {
- //input
- scanf("%d%d",&n,&m);
- vector<Node> stu(n);//student
- map<string, int> stuMap;//for query
- for(int i = 0; i < n; ++i)
- {
- cin>>stu[i].name;
- scanf("%d%d%d", &stu[i].grade[1], &stu[i].grade[2], &stu[i].grade[3]);
- stu[i].grade[0] = stu[i].grade[1]+stu[i].grade[2]+stu[i].grade[3];
- stu[i].bestRank = INF;
- stuMap[stu[i].name] = i;
- }
- //
- for(int i = 0; i < 4; ++i)//for every record
- {
- vector<SortNode> sortNode(n);
- for(int j = 0; j < n; ++j)
- {
- sortNode[j].g = stu[j].grade[i];
- sortNode[j].idx = j;
- }
- sort(sortNode.begin(), sortNode.end(), greater<SortNode>());
- //process the same grade case
- int nowGrade = INF;
- int nowRank = 0;
- for(int j = 0; j < n; ++j)
- {
- if(sortNode[j].g == nowGrade)
- sortNode[j].rank = nowRank;
- else
- {
- sortNode[j].rank = j;
- nowRank = j;
- nowGrade = sortNode[j].g;
- }
- }
- //then compare to select the best rank
- for(int j = 0; j < n; ++j)
- {
- int idx = sortNode[j].idx;
- int rank = sortNode[j].rank;
- if(stu[idx].bestRank > rank)
- stu[idx].bestRank = rank, stu[idx].bestGrade = i;
- }
- }
- //query
- for(int i = 0; i < m; ++i)
- {
- string name;
- cin>>name;
- map<string, int>::iterator it = stuMap.find(name);
- if(it!=stuMap.end())
- {
- int idx = it->second;
- printf("%d %c\n", stu[idx].bestRank+1, CharTable[stu[idx].bestGrade]);
- }
- else printf("N/A\n");
- }
- return 0;
- }
【PAT】1012. The Best Rank (25)的更多相关文章
- PAT甲 1012. The Best Rank (25) 2016-09-09 23:09 28人阅读 评论(0) 收藏
1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- 【PAT甲级】1012 The Best Rank (25 分)
题意: 输入两个整数N,M(<=2000),接着分别输入N个学生的ID,C语言成绩,数学成绩和英语成绩. M次询问,每次输入学生ID,如果该ID不存在则输出N/A,存在则输出该学生排名最考前的一 ...
- 【PAT】1010. 一元多项式求导 (25)
1010. 一元多项式求导 (25) 设计函数求一元多项式的导数.(注:xn(n为整数)的一阶导数为n*xn-1.) 输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数 ...
- 【PAT】1009. Product of Polynomials (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...
- 【PAT】B1070 结绳(25 分)
此题太给其他25分的题丢人了,只值15分 注意要求最终结果最长,而且向下取整 #include<stdio.h> #include<algorithm> using names ...
- 【PAT】1052 Linked List Sorting (25)(25 分)
1052 Linked List Sorting (25)(25 分) A linked list consists of a series of structures, which are not ...
- 【PAT】1060 Are They Equal (25)(25 分)
1060 Are They Equal (25)(25 分) If a machine can save only 3 significant digits, the float numbers 12 ...
- 【PAT】1012. 数字分类 (20)
1012. 数字分类 (20) 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算 ...
- PAT 甲级 1012 The Best Rank (25 分)(结构体排序)
题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
随机推荐
- MYSQL 查看当前用户与数据库版本
问题一: 查看当前用户 select user(); 问题二: 查看数据库版本 select version();
- webpack ------require,ensure
require-ensure和require-amd的区别: require-amd 说明: 同AMD规范的require函数,使用时传递一个模块数组和回调函数,模块都被下载下来且都被执行后才执行回调 ...
- 【二叉树->链表】二叉树结构转双向线性链表结构(先序遍历)
二叉树存储结构属于非线性链表结构,转化成线性链表结构,能简化操作和理解.然而由非线性转线性需要对整个树遍历一次,不同的遍历方式转化结果页不一样.下面以先序为例. 方法一: 递归法.递归遍历二叉树,因为 ...
- 【LeetCode练习题】Candy
分糖果 There are N children standing in a line. Each child is assigned a rating value. You are giving c ...
- #include <boost/asio.hpp>
TCP服务端和客户端 TCP服务端 #include <iostream> #include <stdlib.h> #include <boost/asio.hpp> ...
- JQuery弹出窗口小插件ColorBox
本文来自: Small_陌 http://www.cnblogs.com/wggmqj/archive/2011/11/04/2236263.html 今天在博客园看到一篇<ASP.NET MV ...
- asp:UpdatePanel中js失效问题已解决
1.js function textSAll(o) { o.select(); } var dddd_dd = function () { $(":text").on(" ...
- Mps与Mrp区别
MPS是完成品的计划表,描述一个特定的完成品的生产时间和生产数量.MPS是一个决定完成品生 产排程及可答应量(ATP)的程序.依据MPS,MRP得以计算在该完成品需求之下,所有组件,零件以 至原材 ...
- IE6、7下inline-block不起作用
网上查到资料是给元素设定display:inline-block,再触发layout,设定display:inline;因为所有的浏览器都支持inlie. 即: div{display:inline- ...
- EditText默认不显示光标,不可编辑,点击它,进入编辑状态,光标显示
设置EditText不可编辑,光标不可见: et.setCursorVisible(false); 设置EditText可编辑,光标可见: et.setOnClickListener(new OnCl ...