【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 - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
随机推荐
- python 数据类型之数值型
1.在python在数值的类型大概包括int float complex decimal 1.int 在3.x中它不在有最大值的限制. 2.float它更加连近于C语言中的double 3.compl ...
- Delphi调用安装驱动sys的单元
unit SysDriver; interface uses windows, winsvc; // jwawinsvc; Type TSysDriver = class(TObject) priva ...
- Linux 之Cut命令详解
摘自:http://blog.csdn.net/zsf8701/article/details/7718680 Linux 之Cut命令详解 cut是一个选取命令,就是将一段数据经过分析,取出我们想要 ...
- cf公式专场-续
Benches Time Limit:500MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- Dictionary到List转换中的性能问题 转
本文来自:http://www.cnblogs.com/353373440qq/p/3488367.html 在应用泛型中,我们经常使用Dictionary,经常会用到Dictionary到List的 ...
- ToString()使用方法
1.数字转换到字符串格式说明符说明示例输出C货币2.5.ToString("C")¥2.50D十进制数25.ToString("D5")00025E科学型250 ...
- 一个月AS2.0总结。
来这家公司一个月了,从最初学习它的木块,到流程,到组件,到改动,到自己做. 感觉好快. 1.AS2.0确实比較3.0差距太大.假设不是公司必须使用2.0,我是真不想使用. 2.代码重用性差.相同的代码 ...
- Linux系统安装VM-Tools
安装 vmware-tools的安装包有两个,一个是rpm包,一个是tar包,下面分别是用了这两种方法安装: 一.rpm包安装 1.在启动LINUX 虚拟机之后,在WMWare 的菜单栏中点击&quo ...
- SQL SERVER分区视图
借助SQL SERVER分区视图,可以对SQL中的表进行集中管理,下文将以实例的方式为您详解SQL SERVER分区视图,希望对您学习SQL数据库能有所帮助. SQL SERVER分区视图给我们提供了 ...
- 字符编码介绍及java中的应用
字符编码,就是对日常的控制符号.文字和常用符号的二进制表示.为了准确的表示如何编号,怎么生产八位字节流,Unicode Technical Report (UTR) #17提出现代编码模型的5个层次: ...