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 CME 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 Specification:

Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (≤), 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 CM and E. Then there are M lines, each containing a student ID.

Output Specification:

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

完了,英文不好会死人呀,看了别人的解释才知道,是找出每个学生在A,C,M,E中的最好排名
如果在A、C、M、E排序过程中遇到同样的分数,需要有相同的排名,
比如在A这一科上5个人的成绩分别是100,90,90,88,87的话,排名应该是1,2,2,4,5,
这一点需要格外留意,不然没有办法通过所有测试。

 #include <iostream>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std; struct Data
{
string No;
int num;
int rank;
}; int main()
{
int N, M;
cin >> N >> M;
vector<Data>nums[];//A C M E
unordered_map <string, int>name;//用于学号查找
for (int i = ; i < N; ++i)
{
string No;
int c, m, e;
cin >> No >> c >> m >> e;
name[No]++;
nums[].push_back({ No,(c + m + e) / , });
nums[].push_back({ No,c, });
nums[].push_back({ No,m, });
nums[].push_back({ No,e, });
}
for (int i = ; i < ; ++i)
{
sort(nums[i].begin(), nums[i].end(), [](Data d1, Data d2) {return d1.num > d2.num; });
for (int j = ; j < nums[i].size(); ++j)
{
if (nums[i][j].num == nums[i][j - ].num)//处理相同分数
nums[i][j].rank = nums[i][j - ].rank;
else
nums[i][j].rank = j + ;//要跳过相同排名
}
} for (int j = ; j < M; ++j)
{
string No;
cin >> No;
int a, c, m, e;
if (name[No] == )
cout << "N/A" << endl;
else
{
for (int i = ; i < name.size(); ++i)
{
if (nums[][i].No == No) a = nums[][i].rank;
if (nums[][i].No == No) c = nums[][i].rank;
if (nums[][i].No == No) m = nums[][i].rank;
if (nums[][i].No == No) e = nums[][i].rank;
}
if (a <= c && a <= m && a <= e) cout << a << " " << "A" << endl;
else if (c <= a && c <= m && c <= e) cout << c << " " << "C" << endl;
else if (m <= a && m <= c && m <= e) cout << m << " " << "M" << endl;
else cout << e << " " << "E" << endl;
}
}
return ;
}

最新文章

  1. C# 迪杰斯特拉算法 Dijkstra
  2. jquery mobile button样式设置
  3. ajax请求、servlet返回json数据
  4. NUnit使用详解(一)
  5. 用php逐行读取文件
  6. Java基础学习笔记十三 常用API之正则表达式、Date、DateFormat、Calendar
  7. CSDN的博客搜索功能不又给力了呵呵呵呵
  8. LevelDB源码分析-Bloom Filter
  9. 【Java基础】求出1-100之间偶数和
  10. 第十一章 AtomicInteger源码解析
  11. java消息中间件的使用与简介
  12. 【前端】用javaScript实现实现一个球池的效果
  13. SQL的3个主要组成
  14. fp-growth树创建代码及详细注释
  15. Learning PHP Design Patterns
  16. 分享知识-快乐自己:N及分类(双重循环、递归)实现
  17. 项目中多条数据保存的json实例
  18. lstat函数的使用【学习笔记】
  19. Shell 通配符、元字符、转义符*****
  20. 传值:web.xml传递参数 即在Servlet中获取web.xml里的值

热门文章

  1. VS2010-MFC(常用控件:列表框控件ListBox)
  2. Hexo 博客图片添加至图床---腾讯云COS图床使用。
  3. IK分词器插件
  4. vue-router路由跳转判断用户是否存在
  5. day2-元组、字典、文件操作
  6. 工作中遇到的bug
  7. springboot与热部署
  8. linux 编译安装php选项
  9. vue实现分环境打包步骤(给不同的环境配置相对应的打包命令)
  10. Windows的SEH机理简要介绍