【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 - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
随机推荐
- autofac使用笔记
在之前的项目中用来解耦的使用的轻型IOC框架是unity,它的使用也是很方便的提供在之前的文章的也提到过它的使用方式,但是使用久了之后发现了它的不足之处就是需要配置xml文件来对应的接口和实现的关系. ...
- SQL Server 查看表定义的 2 种方法
方法 1. 用SQL Server Management Studio 第一步找到要查看的表,右键 第二步点设计 方法 2. sp_help @objname = 'tableName' execut ...
- 定制化Azure站点Java运行环境(3)
定制化Azure Website提供的默认的Tomcat和JDK环境 在我们之前的测试中,如果你访问你的WEB站点URL时不加任何上下文,实际上你看到的web界面是系统自带的测试页面index.jsp ...
- android layout的布局
1.android:layout_width.android:layout_heigth 表示控件的大小,长宽 2.andoid:layout_gravity .android:gravity表示控件 ...
- __declspec(dllimport)的作用
是时候总结一下__declspec(dllimport)的作用了.可能有人会问:__declspec(dllimport)和__declspec(dllexport)是一对的,在动态链接库中__dec ...
- Android-PullToRefresh下拉刷新库基本用法
How:(使用) 转自:http://blog.csdn.net/hantangsongming/article/details/42490277 PullToRefresh是一套实现非常好的下拉刷新 ...
- IVM import vector machine
本文为<Kernel Logistic Regression and the Import Vector Machine>的阅读笔记是技法课的课外阅读 Abstract:基于KLR ker ...
- C#打印条码BarTender SDK打印之路和离开之路(web平凡之路)
从来没想过自己会写一篇博客,鉴于这次从未知的探索到一个个难点的攻破再到顺利打印,很想记录这些点滴,让后人少走弯路. 下面走进正题. 需求:取数据库里的相应的字段数据,并生成条形码,可以批量.单条打印. ...
- Android开发中目前流行控件和知识点总结
Android开发中目前流行控件和知识点总结 1.SlidingMenu 滑动菜单 应用案例:Facebook . Path 2.0 .人人.网易新闻 下载地址: https://github.c ...
- css属性pointer-events
绝对定位元素盖住链接或添加某事件handle的元素后,那么该链接的默认行为(页面跳转)或元素事件将不会被触发.现在Firefox3.6+/Safari4+/Chrome支持一个称为pointer-ev ...