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

排名不应该只是简单的排序算法:

比如说  100,100,99,……   得99分是人是 第二名,而不是第三名。

所以,应该先对分数进行排序,然后在更新名次,算法如下:

      SS[].ra=; //第一个肯定是第一名

          int count=;

          for(i=;i<n;i++)

             {

                   if(SS[i].A==SS[i-].A)//A为平均分

                   {

                       SS[i].ra=SS[i-].ra;//ra 平均分排名

                   count++;//如果分数相同,那么名次和前一个相同,计数器++

                   }

                 else

                     {

                        SS[i].ra=SS[i-].ra+count;

                         count=;//计算器记得还原

                     }

          }

AC代码:

 #include <iostream>

 #include <algorithm>

 #include <string>

 using namespace std;

 struct stu

 {

    string ID;

    int A,C,M,E;

    int ra,rc,rm,re;

 };

 stu SS[];

 bool cmp1(stu a,stu b)

 {

     return a.A>b.A;

 }

 bool cmp2(stu a,stu b)

 {

     return a.C>b.C;

 }

 bool cmp3(stu a,stu b)

 {

     return a.M>b.M;

 }

 bool cmp4(stu a,stu b)

 {

     return a.E>b.E;

 }

 int main()

 {

       int n;

       while(cin>>n)

       {

             int m,i;

          cin>>m;

          for(i=;i<n;i++)

          {

                cin>>SS[i].ID>>SS[i].C>>SS[i].M>>SS[i].E;

          }

           for(i=;i<n;i++)

          {

                 SS[i].A=(SS[i].C+SS[i].M+SS[i].E)/;

                     SS[i].ra=;

                     SS[i].rc=;

                     SS[i].rm=;

                     SS[i].re=;

          }

        sort(SS,SS+n,cmp1);

          int count=;

          for(i=;i<n;i++)

             {

                   if(SS[i].A==SS[i-].A)

                   {

                       SS[i].ra=SS[i-].ra;

                               count++;

                   }

                 else

                     {

                        SS[i].ra=SS[i-].ra+count;

                         count=;

                     }

          }

             sort(SS,SS+n,cmp2);

           count=;

          for(i=;i<n;i++)

          {

              if(SS[i].C==SS[i-].C)

                   {

                       SS[i].rc=SS[i-].rc;

                               count++;

                   }

                 else

                     {

                        SS[i].rc=SS[i-].rc+count;

                         count=;

                     }

          }

             sort(SS,SS+n,cmp3);

          count=;

          for(i=;i<n;i++)

          {

              if(SS[i].M==SS[i-].M)

                   {

                       SS[i].rm=SS[i-].rm;

                               count++;

                   }

                 else

                     {

                        SS[i].rm=SS[i-].rm+count;

                         count=;

                     }

          }

             sort(SS,SS+n,cmp4);

          count=;

          for(i=;i<n;i++)

          {

              if(SS[i].E==SS[i-].E)

                   {

                       SS[i].re=SS[i-].re;

                               count++;

                   }

                 else

                     {

                        SS[i].re=SS[i-].re+count;

                         count=;

                     }

          }

               for(i=;i<m;i++)

          {

                   string goal;int j;

               cin>>goal;

                   for(j=;j<n;j++)

                         if(SS[j].ID==goal) break;

           if(j==n) cout<<"N/A"<<endl;

             else{           

                   char high='E';

                   int temp=SS[j].re;

                   if(temp>=SS[j].rm)

                   {

                      high='M';

                      temp=SS[j].rm;

                   }

                   if(temp>=SS[j].rc)

                   {

                      high='C';

                      temp=SS[j].rc;

                   }

                   if(temp>=SS[j].ra)

                   {

                      high='A';

                      temp=SS[j].ra;

                   }

                   cout<<temp<<" "<<high<<endl;

             }

          }

       }

   return ;

 }

The Best Rank (25)(排名算法)的更多相关文章

  1. 在MySQL中实现Rank高级排名函数【转】

    MySQL中没有Rank排名函数,当我们需要查询排名时,只能使用MySQL数据库中的基本查询语句来查询普通排名.尽管如此,可不要小瞧基础而简单的查询语句,我们可以利用其来达到Rank函数一样的高级排名 ...

  2. 在MySQL中实现Rank高级排名函数

    MySQL中没有Rank排名函数,当我们需要查询排名时,只能使用MySQL数据库中的基本查询语句来查询普通排名.尽管如此,可不要小瞧基础而简单的查询语句,我们可以利用其来达到Rank函数一样的高级排名 ...

  3. PAT甲 1012. The Best Rank (25) 2016-09-09 23:09 28人阅读 评论(0) 收藏

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  4. pat1012. The Best Rank (25)

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  5. A1012 The Best Rank (25)(25 分)

    A1012 The Best Rank (25)(25 分) To evaluate the performance of our first year CS majored students, we ...

  6. flink PageRank详解(批量迭代的页面排名算法的基本实现)

    1.PageRank算法原理   2.基本数据准备 /** * numPages缺省15个测试页面 * * EDGES表示从一个pageId指向相连的另外一个pageId */ public clas ...

  7. 1012 The Best Rank (25分) vector与结构体排序

    1012 The Best Rank (25分)   To evaluate the performance of our first year CS majored students, we con ...

  8. 网页排名算法PagaRank

    网页排名算法PageRank PageRank,网页排名,又叫做网页级别.是一种利用网页之间的超链接数据进行计算的方法.它是由Google的两位创始人提出的. 对于用户而言,网页排名一般是比较主观的, ...

  9. 2015最新百度搜索引擎(seo优化)排名算法

    多少年来,对于弄清百度排名算法成为了一代又一代站长的最高目标.随着百度推出了搜索引擎网页质量**,直接揭开了神秘的百度排名算法,这是作为站长福音啊.现在小编就来为大家介绍一下. 首先想要得到直接需要的 ...

  10. 转:Reddit排名算法工作原理

    http://www.aqee.net/how-reddit-ranking-algorithms-work/ 这是一篇继<Hacker News 排名算法工作原理>之后的又一篇关于排名算 ...

随机推荐

  1. SSIS 学习(7):包配置(下)【转】

    经过前面几个章节的学习,我们开发的ETL包算已经完成一大半了,但是还不够完美,正如一场足球比赛,前面大家打得很辛苦,传接得也很漂亮,但 是临门一脚的技术不过关,进不了球,一切都是白搭.今天我们就来为大 ...

  2. android开发之路08(ListView&Adapter)

    ListView控件介绍:用于将数据库中的数据或者网络中的数据通过列表的形式显示出来:ListView采用MVC模式将前端显示和后端数据进行分离. 也就是说,ListView控件在装载数据时并不是直接 ...

  3. JQUERY 动态时钟

    <script type="text/javascript" src="script/jquery-1.8.3.min.js"></scrip ...

  4. Windows 平台下Git 服务器搭建

    由于项目中一直在使用git作为版本管理,自己对git的理解.使用都还不是怎么的熟悉,所以准备深入了解一下git及一些常用命令的使用,于是干脆把服务端架上,通过自己的PC作为服务端同时作为客户端的角色进 ...

  5. Eclipse+Axis自动生成Web Service WSDL文件

    JDK版本:1.5.0_22 Eclipse版本:Helios Service Release 2(3.6.2) 首先创建一个web工程,创建过程如下: 如果选择Apache Tomcat v5.5, ...

  6. tomcat 安装

    升级系统之后很长一段时间没有用tomcat(主要是没做东西),这两天要开始干活了,发现竟然没法发用了....ok,重新整一遍.算是温习. 上次所有环境的搭建基本都是师兄帮我,自己做得东西很少,这次就正 ...

  7. 如何更好的理解(pageX,pageY,clientX,clientY,eventX,eventY,scrollX,scrollY,screenX,screenY,event.offsetX,event.offsetY,offsetLeft,style.left)

    1 pageX,pageY:鼠标指针相对于当前窗口的X,Y坐标,计算区域包括窗口自身的控件和滚动条.(火狐特有) 2 event.clientX,event.clientY:鼠标指针相对于当前窗口的X ...

  8. 【Knockout】四、绑定上下文

    Binding context binding context是一个保存数据的对象,你可以在你的绑定中引用它.当应用绑定的时候,knockout自动创建和管理binding context的继承关系. ...

  9. IntelliJ IDEA 13.x 下使用Hibernate + Spring MVC + JBoss 7.1.1

    从2004年开始做.NET到现在.直到最近要做一些JAVA的项目,如果说100个人写一篇关于.NET的文章,估计这10个人写的内容都是一样.但是如果说10个人写Java的文章,那真的是10个人10种写 ...

  10. 【Cocos2d入门教程一】Cocos2d-x环境搭建

    在进行Cocos2d游戏开发前 我们先来配置一下环境,我们先来准备一下工具,我们所需要的工具分别为: 1.Cocos2d引擎 2.JDK 3.SDK 4.NDK 5.ANT 6.ADT 1.下载Coc ...