PAT Ranking (排名)

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive number N (<=100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (<=300), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.

Output Specification:

For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:

registration_number final_rank location_number local_rank

The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.

Sample Input:

2

5

1234567890001 95

1234567890005 100

1234567890003 95

1234567890002 77

1234567890004 85

4

1234567890013 65

1234567890011 25

1234567890014 100

1234567890012 85

Sample Output:

9

1234567890005 1 1 1

1234567890014 1 2 1

1234567890001 3 1 2

1234567890003 3 1 2

1234567890004 5 1 4

1234567890012 5 2 2

1234567890002 7 1 5

1234567890013 8 2 3

1234567890011 9 2 4

先分组排名,再全部排名

 #include <iostream>

 #include <string>

 #include <algorithm>

 #include <vector>

 using namespace std;

 struct stu

 {

    int loc,frank,lrank,gra;

    string name;

 };

 bool cmp(stu s1,stu s2)

 {

     if(s1.frank==s2.frank)

     return s1.name<s2.name;

       return s1.frank<s2.frank;

 }

 bool cmpg(stu s1,stu s2)

 {

       return s1.gra>s2.gra;

 }

 int main()

 {

   int n;int k;int rank,count;

   int i,j;

     while(cin>>n)

   {

       vector<stu> total;

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

      {

          cin>>k;

             vector<stu> s(k);

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

             {

                cin>>s[j].name>>s[j].gra;

                s[j].loc=i;

             }

             sort(s.begin(),s.end(),cmpg);

             count=;

             s[].lrank=;

             total.push_back(s[]);

             for(j=;j<k-;j++)

             {

                   if(s[j].gra==s[j+].gra)

                   {

                         s[j+].lrank=s[j].lrank;

                         count++;

                   }

                   else

                   {

                       s[j+].lrank=s[j].lrank+count;

                         count=;

                   }

                   total.push_back(s[j+]);

             }

      }

           sort(total.begin(),total.end(),cmpg);

           count=;

             total[].frank=;

             for(j=;j<total.size()-;j++)

             {

                   if(total[j].gra==total[j+].gra)

                   {

                         total[j+].frank=total[j].frank;

                         count++;

                   }

                   else

                   {

                       total[j+].frank=total[j].frank+count;

                         count=;

                   }

             }

             sort(total.begin(),total.end(),cmp);

             cout<<total.size()<<endl;

             for(i=;i<total.size();i++)

                   cout<<total[i].name<<" "<<total[i].frank<<" "<<total[i].loc<<" "<<total[i].lrank<<endl;

   }

   return ;

 }

PAT Ranking (排名)的更多相关文章

  1. 1025 PAT Ranking[排序][一般]

    1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer S ...

  2. 1141 PAT Ranking of Institutions[难]

    1141 PAT Ranking of Institutions (25 分) After each PAT, the PAT Center will announce the ranking of ...

  3. pat1025. PAT Ranking (25)

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  4. PAT_A1141#PAT Ranking of Institutions

    Source: PAT A1141 PAT Ranking of Institutions (25 分) Description: After each PAT, the PAT Center wil ...

  5. PAT_A1025#PAT Ranking

    Source: PAT A1025 PAT Ranking Description: Programming Ability Test (PAT) is organized by the Colleg ...

  6. PAT甲级:1025 PAT Ranking (25分)

    PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...

  7. PAT 甲级 1025 PAT Ranking

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  8. A1025 PAT Ranking (25)(25 分)

    A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...

  9. 1025 PAT Ranking (25分)

    1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...

随机推荐

  1. java.lang.IllegalArgumentException: Service Intent must be explicit: Intent

    在Activity中启动Service的时候报错: 服务意图必须是显性声明. 这是为了防止造成冲突(i.e. 有多个Service用同样的intent-filter的情况) 这是Android 5.0 ...

  2. 如何用拉姆达表达式(Lambda Expressions) 书写左链接查询

    在C#中,如果要实现两个列表的左链接查询,我们的一般用法就是用的linq表达式就是 List<Pet> pets = }, }, } }; List<Pet2> pets2 = ...

  3. [转]W3C 验证 there is no attribute target for this element

    http://validator.w3.org/ 本文转自:http://hi.baidu.com/linkbestlove/item/d7fff865aefa5f0ba1cf0f04 我们要在新窗口 ...

  4. [改善Java代码]不要主动进行垃圾回收

    建议51: 不要主动进行垃圾回收 很久很久以前,在Java 1.1的年代里,我们经常会看到System.gc这样的调用—主动对垃圾进行回收.不过,在Java知识深入人心后,这样的代码就逐渐销声匿迹了— ...

  5. 使用Mat分析大堆信息

    在定位一线问题时经常碰测试中出现Out Of Memory的问题, 通过jmap查看,发现JVM heap全用满了.有很多工具可以查看JVM堆的信息, 收费的比如JProfiler, YourKit, ...

  6. asp.net mvc 的几种分页Pager

    第一种 /// <summary> /// 分页Pager显示 /// </summary> /// <param name="html">&l ...

  7. 只能在执行 Render() 的过程中调用 RegisterForEventValidation(RegisterForEventValidation can only be called during Render();

    只能在执行 Render() 的过程中调用 RegisterForEventValidation(RegisterForEventValidation can only be called durin ...

  8. CSS3秘笈第三版涵盖HTML5学习笔记6~8章

    第二部分----CSS实用技术 第6章,文本格式化 指定备用字体: font-family:Arial,Helvetica,sans-serif; 当访问者没有安装第一种字体时,浏览器会在列表中继续往 ...

  9. Linux 命令 - uniq: 通知或忽略重复行

    给定一个已排好序的文件,uniq 会删除重复行并将结果输出到标准输出中.uniq 通常与 sort 结合使用以删除 sort 输出内容中的重复行. 命令格式 uniq [OPTION]... [INP ...

  10. ASP.NET播客(留言时间,投票IP,留言限字数,上传视频)

    留言发布时间功能: 界面: 前台代码: 在Datalist控件中: 在<%#getIsDate(Convert.ToString(Eval("issuanceDate"))) ...