九度题目1324:The Best Rank

题目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;
}
时间: 2024-08-31 07:30:57

九度题目1324:The Best Rank的相关文章

九度题目1120:全排列

题目1120:全排列  时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2749 解决:669 题目描述: 给定一个由不同的小写字母组成的字符串,输出这个字符串的所有全排列. 我们假设对于小写字母有'a' < 'b' < ... < 'y' < 'z',而且给定的字符串中的字母已经按照从小到大的顺序排列. 输入: 输入只有一行,是一个由不同的小写字母组成的字符串,已知字符串的长度在1到6之间. 输出: 输出这个字符串的所有排列方式,每行一个排列.要求字母序比较小的排列在前

九度题目1110:小白鼠排队

题目1110:小白鼠排队 时间限制:1 秒内存限制:32 兆特殊判题:否提交:1348解决:820 题目描述: N只小白鼠(1 <= N <= 100),每只鼠头上戴着一顶有颜色的帽子.现在称出每只白鼠的重量,要求按照白鼠重量从大到小的顺序输出它们头上帽子的颜色.帽子的颜色用"red","blue"等字符串来表示.不同的小白鼠可以戴相同颜色的帽子.白鼠的重量用整数表示. 输入: 多案例输入,每个案例的输入第一行为一个整数N,表示小白鼠的数目. 下面有N行

九度题目1188:约瑟夫环

题目1188:约瑟夫环 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1500 解决:665 题目描述:     N个人围成一圈顺序编号,从1号开始按1.2.3......顺序报数,报p者退出圈外,其余的 人再从1.2.3开始报数,报p的人再退出圈外,以此类推.     请按退出顺序输出每个退出人的原序号. 输入: 包括一个整数N(1<=N<=3000)及一个整数p. 输出: 测试数据可能有多组,对于每一组数据, 按退出顺序输出每个退出人的原序号. 样例输入: 7 3 样例输出:

九度题目1008:最短路径问题

题目1008:最短路径问题 时间限制:1 秒内存限制:32 兆特殊判题:否提交:5129解决:1634 题目描述: 给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花 费,如果最短距离有多条路线,则输出花费最少的. 输入: 输入n,m,点的编号是1~n,然后是m行,每行4个数 a,b,d,p,表示a和b之间有一条边,且其长度为d,花费为p. 最后一行是两个数 s,t;起点s,终点t.n和m为0时输入结束. (1n=1000, 0m100000,

九度题目1009:二叉搜索树

题目1009:二叉搜索树 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4308 解决:1919 题目描述: 判断两序列是否为同一二叉搜索树序列 输入: 开始一个数n,(1<=n<=20) 表示有n个需要判断,n= 0 的时候输入结束. 接下去一行是一个序列,序列长度小于10,包含(0~9)的数字,没有重复数字,根据这个序列可以构造出一颗二叉搜索树. 接下去的n行有n个序列,每个序列格式跟第一个序列一样,请判断这两个序列是否能组成同一颗二叉搜索树. 输出: 如果序列相同则输出YES

九度题目1201:二叉排序树

题目1201:二叉排序树 时间限制:1 秒内存限制:32 兆特殊判题:否提交:3008解决:1262 题目描述:     输入一系列整数,建立二叉排序数,并进行前序,中序,后序遍历. 输入:     输入第一行包括一个整数n(1=n=100).     接下来的一行包括n个整数. 输出:     可能有多组测试数据,对于每组数据,将题目所给数据建立一个二叉排序树,并对二叉排序树进行前序.中序和后序遍历.     每种遍历结果输出一行.每行最后一个数据之后有一个空格. 样例输入: 5 1 6 5

九度题目1363:欢乐斗地主

欢乐斗地主 时间限制:1 秒内存限制:32 兆特殊判题:否提交:727解决:163 题目描述:               如果大家玩过欢乐斗地主这个游戏,就一定知道有一个具有"提示"功能的按钮.如果你不知道你现在手 里的牌有没有比上家大的牌,并且你也懒得去一张一张地看你手中的牌.这时候你就可以点"提示"按钮,系 统会告诉你是否有这样的牌.          如果你是一个喜欢挑战的人,你就一定会想,能不能写一个程序,让它实现欢乐斗地主中的"提示"

九度题目1027:欧拉回路

题目1027:欧拉回路 时间限制:1 秒内存限制:32 兆特殊判题:否提交:2344解决:1157 题目描述:     欧拉回路是指不令笔离开纸面,可画过图中每条边仅一次,且可以回到起点的一条回路.现给定一个图,问是否存在欧拉回路? 输入:     测试输入包含若干测试用例.每个测试用例的第1行给出两个正整数,分别是节点数N ( 1 < N < 1000 )和边数M:随后的M行对应M条边,每行给出一对正整数,分别是该条边直接连通的两个节点的编号(节点从1到N编号).当N为0时输入结束. 输出:

九度题目1153:括号匹配问题

题目1153:括号匹配问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2965 解决:1315 题目描述:     在某个字符串(长度不超过100)中有左括号.右括号和大小写字母:规定(与常见的算数式子一样)任何一个左括号都从内到外与在它右 边且距离最近的右括号匹配.写一个程序,找到无法匹配的左括号和右括号,输出原来字符串,并在下一行标出不能匹配的括号.不能匹配的 左括号用"$"标注,不能匹配的右括号用"?"标注. 输入:     输入包括多组数据,