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. json字符串参数

    jsp部分        json字符串的属性应该都是实体类的属性 function saveCashier(){ layer.closeAll(); var Reapply = document.g ...

  2. maven项目添加websocket

    最近由于项目业务需求,需要用到websocket来实现即时信息的推送,学习了一下websocket,网上搜了一下学习教程,很多版本看的我云里雾里,最后选择用tomcat提供的最新版本(tomcat 启 ...

  3. 替换ubuntu 14.04的源

    1. 背景(为什么要替换)安装ubuntu,默认源是(http://extras.ubuntu.com/ubuntu),国内访问很慢...当我们用apt-get安装软件包或者更新时有时很慢,所以才想到 ...

  4. php中switch语句case后表达式写法记录一

    可作等级评价: $var = 95; switch(true){ case $var < 100; $level = 1; break; case $var < 95; $level = ...

  5. HttpURLConnection传JSON数据

    try { //创建连接 URL url = new URL(url); HttpURLConnection connection = (HttpURLConnection) url.openConn ...

  6. BOGEER博格尔YT-813码表使用说明书 (我的是YT-823)

    BOGEER博格尔YT-813码表使用说明书.doc 源:http://w.gdu.me/wiki/Bike/BOGEER-YT-813.html 参数设置 首先要测量出车轮的周长,测出车轮周长后按住 ...

  7. layoutSubviews在什么情况下会被调用

    layoutSubviews在以下情况下会被调用: 1.init初始化不会触发layoutSubviews. 2.addSubview会触发layoutSubviews. 3.设置view的Frame ...

  8. CodeForces 670F Restore a Number

    模拟. 首先暴力找到答案的位数,然后就是分类讨论输出答案. #pragma comment(linker, "/STACK:1024000000,1024000000") #inc ...

  9. jenkins jmeter持续集成批处理jmx脚本

    这篇文章介绍jenkis jmeter的持续集成,利用jenkins定时任务去批处理执行jmeter的jmx脚本文件,并且生成测试报告 1:jmeter的安装这里我就不在赘述了,如有问题可参考我的jm ...

  10. VM10下Ubuntu无法安装vim的问题

    今天在VM10下重装了Ubuntu14.10,安装vim时发现如下问题 谷歌了一下,终于找到一种方法解决. 终端下: sudo vi /etc/apt/source.list 该命令将用vi打开一个文 ...