1012 The Best Rank (25)(25 分)

1012 The Best Rank (25)(25 分)

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 Algebra), 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

 

水 处理下就行,自己写的代码我都想吐 好长

对了还长了一个姿势就是..map如果对应的值是结构体的话

可以采用mp.count(...key)。。。。。。。判断是否大于0来判断是否存在这个东西    嘿嘿

第三个测试点就是..针对哪种并且排名的  以下这种测试样例对应该就全对了吧

5 6
001 98 97 96
002 98 94 95
003 98 92 96
004 97 91 94
005 97 90 89
001
1 A
002
1 C
003
1 C
0004
N/A
004
2 C
005
2 C

 

 

代码:

#include<bits/stdc++.h>
using namespace std;
struct node
{	
	int id;
	int C,M,A,E;
	int ranc,rana,ranm,rane;
	bool operator <(const node & a)const{
		return this->C > a.C;
	} 
}s[2005];
map<string,int>tt;
map<int,node>mp;
int round(node tmp){
	int sum = tmp.C + tmp.M + tmp.E;
	double gg = sum * 1.0 /3;
	if(gg - int(gg) -0.5 >= 0)
		gg++;
	return gg;
}
bool cmp1(node a,node b){
	return a.A > b.A;
}
bool cmp2(node a,node b){
	return a.C > b.C;
}
bool cmp3(node a,node b){
	return a.M > b.M;
}
bool cmp4(node a,node b){
	return a.E > b.E;
}
int main() {
	int n,m;
	char str[100];
	scanf("%d%d",&n,&m);
	for(int i = 1; i <= n; i++){
		s[i].id = i;
		scanf("%s %d %d %d",str,&s[i].C,&s[i].M,&s[i].E);
		s[i].A = round(s[i]);
		tt[str] = i;
		mp[i] = s[i];
	}
	sort(s+1,s+1+n,cmp1);//这个是以a为排序的 
	int now = 1 ,cnt = 0; 
	for(int i = 1 ; i <= n ; i++){
		if(i == 1){
			s[i].rana = 1;
			cnt++; 
		}
		else{
			if(s[i].A == s[i-1].A)
				s[i].rana = s[i-1].rana,cnt++;
			else{
				now += cnt;
				s[i].rana = now;
				cnt = 1;	
			}
		}
	}
	
	sort(s+1,s+1+n,cmp2);//以c为排序 
	now = 1,cnt = 0; 
	for(int i = 1 ; i <= n ; i++){
		if(i == 1){
			cnt++;
			s[i].ranc = 1;
		}
		else{
			if(s[i].C == s[i-1].C)
				s[i].ranc = s[i-1].ranc,cnt++;
			else{
				now += cnt;
				s[i].ranc = now;
				cnt = 1;	
			}
		}
	}
	
	
	sort(s+1,s+1+n,cmp3);//以m为排序 
	now = 1 ,cnt = 0; 
	for(int i = 1 ; i <= n ; i++){
		if(i == 1){
			s[i].ranm = 1;
			cnt++;
		}
		else{
			if(s[i].M == s[i-1].M)
				s[i].ranm = s[i-1].ranm,cnt++;
			else{
				now += cnt;
				s[i].ranm = now;
				cnt = 1;	
			}	
		}
		
	}
	
	sort(s+1,s+1+n,cmp4);//以e为排序 
	now = 1,cnt = 0; 
	for(int i = 1 ; i <= n ; i++){
		if(i == 1){
			s[i].rane = 1;
			cnt++;
		}
		else{
			if(s[i].E == s[i-1].E)
				s[i].rane = s[i-1].rane,cnt++;
			else{
				now += cnt;
				s[i].rane = now;
				cnt = 1;	
			}	
		}
		mp[s[i].id] = s[i];
	}
	//以下是针对输出的没有毛病	
	for(int k = 1 ; k <= m; k++){
		scanf("%s",str);
		int gg = tt[str];
		node tmp = mp[gg];
		if(tt[str] == 0){
			printf("N/A\n");
			continue;
		}	
		int minn = tmp.rana;
		char ch = 'A';
		if(tmp.ranc < minn){
			minn = tmp.ranc;
			ch = 'C';
		}
		if(tmp.ranm < minn){
			minn = tmp.ranm;
			ch = 'M';
		}
		if(tmp.rane < minn){
			minn = tmp.rane;
			ch = 'E';
		}
		printf("%d %c\n",minn,ch);
	}
	return 0;
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值