1012 The Best Rank

该文介绍了一个用于评估和排名计算机科学一年级学生表现的系统。系统基于C语言、数学和英语三门课程的成绩,以及平均成绩进行排名。每个学生获得四个排名:C、M、E和A,分别对应三门课程和平均成绩的最佳排名。文章提供了示例数据和算法实现,包括如何处理同分情况,并展示了如何根据学生ID查询其最佳排名。
摘要由CSDN通过智能技术生成

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.

解题思路:有可能存在同分情况,下标为0肯定是第一名,如果与前面分数不一样那就排名加一

输入

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 CM and E. Then there are M lines, each containing a student ID.

输出

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.

#include<iostream>
#include<unordered_map>
#include<algorithm>
using namespace std;

struct student{
	string ID;
	int grade[4],rank[4];
};

	bool comp0(student x,student y){
		return x.grade[0]>y.grade[0];
	}
	bool comp1(student x,student y){
		return x.grade[1]>y.grade[1];
	}
	bool comp2(student x,student y){
		return x.grade[2]>y.grade[2];
	}
	bool comp3(student x,student y){
		return x.grade[3]>y.grade[3];
	}
	
	int main(){
	student s[2000];
	int N,M,i,j,k,l;
	cin>>N>>M;
	for(i=0;i<N;i++){
		string temp;
		cin>>temp>>j>>k>>l;
		s[i].ID=temp;
		s[i].grade[0]=(j+k+l)/3;
		s[i].grade[1]=j;
		s[i].grade[2]=k;
		s[i].grade[3]=l;
	}
	sort(s,s+N,comp0);
	for(i=0;i<N;i++){
		if(i==0||s[i].grade[0]!=s[i-1].grade[0])j=i+1;
		s[i].rank[0]=j;
    //有可能存在同分情况,下标为0肯定是第一名,如果与前面分数不一样那就排名加一
	}//根据C排名
	sort(s,s+N,comp1);
	for(i=0;i<N;i++){
		if(i==0||s[i].grade[1]!=s[i-1].grade[1])j=i+1;
		s[i].rank[1]=j;
	}//根据M
	sort(s,s+N,comp2);
	for(i=0;i<N;i++){
		if(i==0||s[i].grade[2]!=s[i-1].grade[2])j=i+1;
		s[i].rank[2]=j;
	}//根据E
	sort(s,s+N,comp3);
	for(i=0;i<N;i++){
		if(i==0||s[i].grade[3]!=s[i-1].grade[3])j=i+1;
		s[i].rank[3]=j;
	}//根据A
	
	unordered_map<string,int>MAP;
	for(i=0;i<N;i++)MAP[s[i].ID]=i;//建立哈希表
	while(M--){
        //应对M次的查询
		string temp;
		cin>>temp;
		if(!MAP.count(temp)){
            //如果没有temp
			cout<<"N/A"<<endl;
		}
		else{
            //如果有temp
			i=MAP[temp];
			int minrank=10000;
            //找到哪一科最好,排名是多少
			for(j=0;j<4;j++){
				if(minrank>s[i].rank[j])minrank=s[i].rank[j];
			}
			if(minrank==s[i].rank[0])cout<<minrank<<' '<<'A'<<endl;
			else if(minrank==s[i].rank[1])cout<<minrank<<' '<<'C'<<endl;
			else if(minrank==s[i].rank[2])cout<<minrank<<' '<<'M'<<endl;
			else if(minrank==s[i].rank[3])cout<<minrank<<' '<<'E'<<endl;
		}
	}
} 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值