IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> PAT--1012 The Best Rank(C语言) -> 正文阅读

[C++知识库]PAT--1012 The Best Rank(C语言)

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

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

?注意点:如果相同分数,名次要一样~😓

解析:通过4个排序规则选出最好名字,可以利用两个map分别存贮最好名次和相应领域。

#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;
map<int,int> mp1;//存储最好名次
map<int,char> mp2;//存储对应领域
struct s
{
	int c,m,e,a,id;	
}a[2005];
bool cm1(s x,s y)	//按照A排序
{
	return x.a>y.a;	
}
bool cm2(s x,s y)	//按照C排序
{	
	return x.c>y.c;	
}
bool cm3(s x,s y)	//按照M排序
{
	return x.m>y.m;	
}
bool cm4(s x,s y)	//按照E排序
{
	return x.e>y.e;
}
int main()
{
	int n,m,i;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++) scanf("%d%d%d%d",&a[i].id,&a[i].c,&a[i].m,&a[i].e),a[i].a=(a[i].c+a[i].m+a[i].e)/3;
	//按照A排序	
	sort(a,a+n,cm1);
	for(i=0;i<n;i++)
	{
		if(i==0) mp1[a[i].id]=i+1,mp2[a[i].id]='A';//第一个不用考虑同分
		else{
			int f=a[i].a,p=i;
			while(p>=1&&f==a[p-1].a) p--;//跟同分相同排名
			mp1[a[i].id]=p+1,mp2[a[i].id]='A';
		}
	}	
	//按照C排序
	sort(a,a+n,cm2);	
	for(i=0;i<n;i++)
	{
			int f=a[i].c,p=i;
			while(p>=1&&f==a[p-1].c) p--;
			if(p+1<mp1[a[i].id]) mp1[a[i].id]=p+1,mp2[a[i].id]='C';//如果名词更考前,更新
	}
	//按照M排序
	sort(a,a+n,cm3);
	for(i=0;i<n;i++)
	{
			int f=a[i].m,p=i;
			while(p>=1&&f==a[p-1].m) p--;
			if(p+1<mp1[a[i].id]) mp1[a[i].id]=p+1,mp2[a[i].id]='M';
	}
	//按照E排序
	sort(a,a+n,cm4);
	for(i=0;i<n;i++)
	{
			int f=a[i].e,p=i;
			while(p>=1&&f==a[p-1].e) p--;
			if(p+1<mp1[a[i].id]) mp1[a[i].id]=p+1,mp2[a[i].id]='E';
	}		
	while(m--)
	{
		int id;
		scanf("%d",&id);
		if(mp1[id]) printf("%d %c\n",mp1[id],mp2[id]);
		else printf("N/A\n");//不存在
	}	
	return 0;
}

  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2022-09-30 00:33:07  更:2022-09-30 00:37:35 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/19 4:49:17-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码