题目链接: 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)的更多相关文章

  1. 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 ...

  2. 【PAT甲级】1012 The Best Rank (25 分)

    题意: 输入两个整数N,M(<=2000),接着分别输入N个学生的ID,C语言成绩,数学成绩和英语成绩. M次询问,每次输入学生ID,如果该ID不存在则输出N/A,存在则输出该学生排名最考前的一 ...

  3. 【PAT】1010. 一元多项式求导 (25)

    1010. 一元多项式求导 (25) 设计函数求一元多项式的导数.(注:xn(n为整数)的一阶导数为n*xn-1.) 输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数 ...

  4. 【PAT】1009. Product of Polynomials (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1009 分析:简单题.相乘时指数相加,系数相乘即可,输出时按指数从高到低的顺序.注意点:多项式相 ...

  5. 【PAT】B1070 结绳(25 分)

    此题太给其他25分的题丢人了,只值15分 注意要求最终结果最长,而且向下取整 #include<stdio.h> #include<algorithm> using names ...

  6. 【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 ...

  7. 【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 ...

  8. 【PAT】1012. 数字分类 (20)

    1012. 数字分类 (20) 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算 ...

  9. PAT 甲级 1012 The Best Rank (25 分)(结构体排序)

    题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...

随机推荐

  1. KeybMap 键盘映射工具更新至 V1.5(修订)

    KeybMap 更新至 V1.5,主要是增加了对一些多媒体键定义修改功能,也可以将任意一键定义为打开指定的程序. 3月9日略做修订. http://www.mympc.org/down/1/2005- ...

  2. linux之SQL语句简明教程---LIKE

    LIKE 是另一个在 WHERE 子句中会用到的指令.基本上,LIKE 能让我们依据一个套式 (pattern) 来找出我们要的资料.相对来说,在运用 IN 的时候,我们完全地知道我们需要的条件:在运 ...

  3. 【Java接口实现动态加载不同的类】

    public interface Person {       public double calcuMonthlySalary(double sal, int type);    }   publi ...

  4. Makefile里面的$(MAKE)到底是啥

    [已解决]Makefile里面的$(MAKE)到底是啥 [复制链接] http://bbs.chinaunix.net/thread-4164499-1-1.html make 定义了很多默认变量,像 ...

  5. linux中的strings命令简介

    摘自:http://blog.csdn.net/stpeace/article/details/46641069 linux中的strings命令简介 在linux下搞软件开发的朋友, 几乎没有不知道 ...

  6. 关于select

    select 1与select * 的区别:“selelct 常量 from 表名” 对应所有行,返回的永远只有一个值,即常量 ,所以一般只用来判断是否有表记录:而“select * from 表名” ...

  7. 每日一dp(2)——龟兔赛跑(hdu 2059)

    比較经典的动态规划的题目了 一般动态规划的想法都是先推断是否有最优子结构,无后效性.接着从状态转移入手,尽量细分状态(即给定N得到N+1),完了再递推计算 难点:转移方程,其一般也难在怎样描写叙述一个 ...

  8. 【剑指offer】连续子数组的最大和

    个開始,到第3个为止).你会不会被他忽悠住? 输入: 输入有多组数据,每组測试数据包括两行. 第一行为一个整数n(0<=n<=100000),当n=0时,输入结束.接下去的一行包括n个整数 ...

  9. optimizer for eclipse--Eclipse优化,让你的Eclipse快来飞!

    官方网站:http://zeroturnaround.com/free/optimizer-for-eclipse/ infoq网址:http://www.infoq.com/cn/news/2015 ...

  10. 自动工作负载库(Automatic Workload Repository,AWR)

    自动工作负载库(Automatic Workload Repository,AWR)AWR的由来:    10g之前的oracle:用户的连接将产生会话,当前会话记录保存在v$session中:处于等 ...