1. 云栖社区>
  2. 博客列表>
  3. 正文

九度题目1324:The Best Rank

光仔december 2014-07-06 09:14:00 浏览185 评论0

摘要: 题目1324:The Best Rank 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:414 解决:107 题目描述: To evaluate the performance of our first year CS majored students, we consider t...

题目1324:The Best Rank
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:414
解决:107
题目描述:
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.


输入:
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.


输出:
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".


样例输入:
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样例输出:
1 C
1 M
1 E
1 A
3 A
N/A

 

代码:

/*二维数组的横纵向排序问题,用到了结构体,注意成绩相同
同学的排名,题很水,但是比较麻烦,特别适合马虎的人做(我就是)*/
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
 int ID,C,M,E,A;//学生的编号,三科的成绩和平均成绩
 int PC,PM,PE,PA;//这几科的排名
 int con;//最高排名的成绩
 char val;//最高排名的课的名字
}stu[2500];
int cmp1(node a,node b)//按C成绩排序
{
    if(a.C!=b.C) return a.C>b.C;
}
int cmp2(node a,node b)//按M成绩排序
{
    if(a.M!=b.M) return a.M>b.M;
}
int cmp3(node a,node b)//按E成绩排序
{
    if(a.E!=b.E) return a.E>b.E;
}
int cmp4(node a,node b)//按平均成绩排序
{
    if(a.A!=b.A) return a.A>b.A;
}
int min(int n,int m)
{return n<m?n:m;}
int main()
{
 int i,j,n,m,x;
 while(scanf("%d %d",&n,&m)!=EOF)
 {
  memset(stu,0,sizeof(stu));
  for(i=0;i<n;i++)
        {
            scanf("%d %d %d %d",&stu[i].ID,&stu[i].C,&stu[i].M,&stu[i].E);
   stu[i].A=(stu[i].C+stu[i].M+stu[i].E)/3;
  }

  //假设四个人的C成绩为 90 90 80 70 则排名为 1 1 3 4
  //所以注意成绩一样的同学,排名是一样的(第三个人的排名是3而不是二)
  sort(stu,stu+n,cmp1);
  for(i=0;i<n;i++)
  {
   if(i==0)
            stu[i].PC=i+1;

   if(i!=0&&stu[i].C!=stu[i-1].C)
   stu[i].PC=i+1;

   if(i!=0&&stu[i].C==stu[i-1].C)
   stu[i].PC=stu[i-1].PC;
  }
  sort(stu,stu+n,cmp2);
  for(i=0;i<n;i++)
  {
   if(i==0)
            stu[i].PM=i+1;

   if(i!=0&&stu[i].M!=stu[i-1].M)
   stu[i].PM=i+1;

   if(i!=0&&stu[i].M==stu[i-1].M)
   stu[i].PM=stu[i-1].PM;
  }
  sort(stu,stu+n,cmp3);
  for(i=0;i<n;i++)
  {
   if(i==0)
            stu[i].PE=i+1;

   if(i!=0&&stu[i].E!=stu[i-1].E)
   stu[i].PE=i+1;

   if(i!=0&&stu[i].E==stu[i-1].E)
   stu[i].PE=stu[i-1].PE;
  }
  sort(stu,stu+n,cmp4);
  for(i=0;i<n;i++)
  {
   if(i==0)
            stu[i].PA=i+1;

   if(i!=0&&stu[i].A!=stu[i-1].A)
   stu[i].PA=i+1;

   if(i!=0&&stu[i].A==stu[i-1].A)
   stu[i].PA=stu[i-1].PA;
  }

  for(i=0;i<n;i++)
  {
   stu[i].con=min(min(stu[i].PC,stu[i].PM),min(stu[i].PE,stu[i].PA));//得到最高排名
   //得到最高排名的科目名称(相同的按优先级较高的为准)
   if(stu[i].PA==stu[i].con) stu[i].val='A';
   else
   {
      if(stu[i].PC==stu[i].con) stu[i].val='C';
      else
      {
      if(stu[i].PM==stu[i].con) stu[i].val='M';
         else
      {
       if(stu[i].PE==stu[i].con) stu[i].val='E';
      }
      }
   }
  }

  int flag;
  for(i=0;i<m;i++)
  {
   scanf("%d",&x);
   flag=0;
   for(j=0;j<n;j++)
   {
    if(x==stu[j].ID)
    {
     printf("%d %c\n",stu[j].con,stu[j].val);
     flag=1;
    }
    if(flag==1)
     break;
   }
   if(flag==0)
    printf("N/A\n");
  }
 }
 return 0;
}
版权声明:本文内容由互联网用户自发贡献,本社区不拥有所有权,也不承担相关法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至:yqgroup@service.aliyun.com 进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。

用云栖社区APP,舒服~

【云栖快讯】哪个编程语言最热门?各个专业领域的技术趋势是什么?如何才能更快速的踏上技术进阶之路……云栖社区2017中国开发者大调查火热进行!答卷可抽奖,红轴机械键盘、天猫精灵,丰富好礼大概率抽取  详情请点击

网友评论

关注
光仔december
目前致力于JavaEE(struts/hibe...
696篇文章|17关注
为您提供简单高效、处理能力可弹性伸缩的计算服务,帮助您快速构建更稳定、安全的应用,提升运维效率,降低 IT 成本... 更多>

RDS是一种稳定可靠、可弹性伸缩的在线数据库服务。支持MySQL、SQL Server、PostgreSQL、高... 更多>
安全技术百问

安全技术百问