【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 - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
随机推荐
- 在WPF中自定义你的绘制(一)
原文:在WPF中自定义你的绘制(一) 在WPF中自定义你的绘制(一) ...
- thinkPHP模板引擎案例
1.if <if condition="$vo.business eq LS"> 零售 <elseif condition="$vo.business ...
- FPGA的SPI从机模块实现
一. SPI总线协议 SPI(Serial Peripheral Interface)接口,中文为串行外设接口.它只需要3根线或4根线即可完成通信工作(这里讨论4根线的情况). ...
- Pet(dfs+vector)
Pet Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- IOS 开展 分别制定了iphone 和 ipad 好? 或开发一个 Universal好?
最近因为工作的需要,.因为时间短的开发周期 开发的需要 积 至iphone 和 ipad 台 执行 优势的版本号 1.安装包,轻松管理,分布 2.您下载iphone,ipad 会自己主动下载 3.审核 ...
- 使用CSS3 Media Queries实现网页自适应(转)
当今银屏分辨率从 320px (iPhone)到 2560px (大屏显示器)或者更大.人们也不再仅仅用台式机来浏览网页,现在有手机,平板电脑等等.所以传统的固定宽度设计形式将不再是个最佳选择,网页设 ...
- Linux下配置VNC
1.确认是否安装vnc服务端 : rpm -q tigervnc-server 默认是没有安装的,需要在Linux系统文件Packages文件夹找到vnc安装包(里面有两个分别是客户端与服务端)tig ...
- 华为S5700基础配置----备份和恢复配置文件
一:备份配置文件 设备作为FTP服务器,用户PC作为FTP客户端 # 配置设备的FTP功能及FTP用户信息. <HUAWEI> system-view [HUAWEI] ftp serve ...
- JQuery弹出层,点击按钮后弹出遮罩层,有关闭按钮
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
- Linux系统学习笔记:文件I/O
Linux支持C语言中的标准I/O函数,同时它还提供了一套SUS标准的I/O库函数.和标准I/O不同,UNIX的I/O函数是不带缓冲的,即每个读写都调用内核中的一个系统调用.本篇总结UNIX的I/O并 ...