1025. PAT Ranking (25)

时间限制
200 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 "algorithm"
#include "string"
#include "vector"
using namespace std;

struct Student
{
string id;
int grade;
int final_rank;
int local;
int local_rank;
};
bool gradecompare(Student a,Student b)
{
if(a.grade !=b.grade)
return a.grade > b.grade;
else return a.id<b.id;
}
vector<Student> stu;

int main()
{
int n,m,count=0;
int start=0;
cin >> n;
Student t;
while(count<n)
{
cin >> m;
for(int i=0;i<m;i++)
{
cin >> t.id >> t.grade;
stu.push_back(t);
}
sort(stu.begin()+start,stu.end(),gradecompare);

for(int i=0+start;i<stu.size();i++)
{
stu[i].local = count+1;
stu[i].local_rank = i+1-start;
if(i>0)
{
if(stu[i].grade==stu[i-1].grade)
stu[i].local_rank = stu[i-1].local_rank;
}

}
start +=m;
count++;
}
sort(stu.begin(),stu.end(),gradecompare);
for(int i=0;i<stu.size();i++)
{
stu[i].final_rank = i+1;
if(i>0)
{
if(stu[i].grade==stu[i-1].grade)
stu[i].final_rank = stu[i-1].final_rank;
}

}
cout<<start<<endl;
vector<Student>::iterator it=stu.begin();
while(it!=stu.end())
{
cout<<(*it).id<<" "<<(*it).final_rank<<" "<<(*it).local<<" "<<(*it).local_rank<<endl;
it++;
}

return 0;
}

浙大pat 1025题解的更多相关文章

  1. 浙大pat 1035题解

    1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...

  2. 浙大pat 1011题解

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  3. 浙大PAT 7-06 题解

    #include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...

  4. 浙大pat 1012题解

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

  5. 浙大 pat 1003 题解

    1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  6. 浙大 pat 1038 题解

    1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  7. 浙大 pat 1047题解

    1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...

  8. 浙大pat 1054 题解

    1054. The Dominant Color (20) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Behind the scen ...

  9. 浙大pat 1059 题解

    1059. Prime Factors (25) 时间限制 50 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...

随机推荐

  1. Iperf[转]

    原文链接:https://openmaniak.com/iperf.php Iperf is a tool to measure the bandwidth and the quality of a ...

  2. django 学习笔记(一)搭建基础环境

    1.安装django 下载地址 https://github.com/django/django 解压后进入文件夹运行指令 >> python setup.py install 2.创建工 ...

  3. 将Cygwin Emacs设为Windows explorer默认打开程序

    由于我在平日的学习与工作中会经常用到Cygwin中的Emacs,很自然地想到应该将emacsclient作为指定文件类型在Windows explorer中的默认打开程序.这样,便可以直接双击文件后在 ...

  4. VMware安装ubuntu,通过/mnt/hgfs 挂载共享Windows系统文件夹

    网上各种相关的配置说明,但是都没一个完整的,在这里楼主结合实战亲测,这一整套包含各种情况 1.安装VMware tools 2.解压到任意一个文件夹 tar -xzvf VMwareTools**** ...

  5. HDU 4403 A very hard Aoshu problem

    暴力$dfs$. 先看数据范围,字符串最长只有$15$,也就是说枚举每个字符后面是否放置“$+$”号的复杂度为${2^{15}}$. 每次枚举到一种情况,看哪些位置能放“$=$”号,每个位置都试一下, ...

  6. 9款.net反编译的必备神器

    编辑来给大家盘点下.net的反编译工具: 1.Reflector Reflector是最为流行的.Net反编译工具.Reflector是由微软员工Lutz Roeder编写的免费程序.Reflecto ...

  7. cp执行命令,如何直接覆盖不提示

    参数说明 -i, --interactive prompt before overwrite (overrides a previous -n option)   #文件存在是,交互式提示是否覆盖 - ...

  8. maven中在本地maven仓库添加jar包

    Maven 手动添加 JAR 包到本地仓库 Maven 确确实实是个好东西,用来管理项目显得很方便,但是如果是通过 Maven 来远程下载 JAR 包的话,我宿舍的带宽是4兆的,4个人共用,有时候用  ...

  9. Tomcat内存溢出

    Tomcat内存溢出的三种情况及解决办法分析 转载于网络  Tomcat内存溢出的原因 在生产环境中tomcat内存设置不好很容易出现内存溢出.造成内存溢出是不一样的,当然处理方式也不一样. 这里根据 ...

  10. C# 语言规范_版本5.0 (第16章 异常)

    1. 异常 C# 中的异常用于处理系统级和应用程序级的错误状态,它是一种结构化的.统一的和类型安全的处理机制.C# 中的异常机制非常类似于 C++ 的异常机制,但是有一些重要的区别: 在 C# 中,所 ...