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. Maven之(二)Maven生命周期

    我们在开发项目的时候,不断地在编译.测试.打包.部署等过程,maven的生命周期就是对所有构建过程抽象与统一,生命周期包含项目的清理.初始化.编译.测试.打包.集成测试.验证.部署.站点生成等几乎所有 ...

  2. FZU 2086 餐厅点餐(模拟)

    Problem 2086 餐厅点餐 Problem Description Jack最近喜欢到学校餐厅吃饭,好吃干净还便宜. 在学校餐厅,有a种汤,b种饭,c种面条,d种荤菜,e种素菜. 为了保证膳食 ...

  3. win8 or win7安装ubuntu双系统

    安装双系统的效果 现在使用win和linux双系统,整个环境相当方便好用,比如在Linux系统上,仍能访问NTFS(win的文件系统格式)中的文件和文档,当然win下的一些像matlab.vs等是不能 ...

  4. ios之极光推送消息收到以后对消息的处理总结

    当我们的APP收到推送消息后,通常需要根据推送内容点击消息进入到指定的页面 这里讲一下收到推送消息后的处理,分为三种情况 :1.APP处于前台运行情况下     2.APP处于后台挂起情况下   3. ...

  5. SASS相关

    1.安装ruby http://rubyinstaller.org/downloads/ 2.安装SASS gem sources --remove https://rubygems.org/ gem ...

  6. Linux scp命令

    语法 scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P p ...

  7. centos 6.5 安装composer

    1.下载composer curl -sS https://getcomposer.org/installer | php ps:如果出现php无法运行的情况,请先把PHP加入环境变量,具体操作参考& ...

  8. Html5移动端页面自适应布局详解(阿里rem布局)

    在移动设备上进行网页的重构或开发,首先得搞明白的就是移动设备上的viewport,通读网上的各种对于viewport的解释之后 大概viewport可以理解为三种 1.layout viewport  ...

  9. JTree单击事件

    import javax.swing.*; import javax.swing.tree.*; import java.awt.FlowLayout; import java.awt.GridLay ...

  10. Java多线程的信号量

    Java的信号量主要的作用是控制线程对资源的访问例如我一个线程池里面有100个线程等待执行,但是我允许最多同时运行5个线程,这5个线程只有其中一个线程执行完毕后,在线程池中等待的线程才能进入开始执行, ...