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. JavaEE XML DOM创建

    DOM创建XML @author ixenos 1.思路: 先封装构建一颗DOM树,然后将DOM树转换成XML文件 2.三种写DOM树到XML文件的方式: 1)使用DOM(或DOM4J.JDOM) 2 ...

  2. CentOS+OpenCV图像的读入、显示

    以管理员身份运行su root输入密码 定位到自己的桌面目录 gedit 1.cpp 编辑内容 #include<opencv2/opencv.hpp>using namespace cv ...

  3. Ubuntu安装Python机器学习包

    1.安装pip $ mkdir ~/.pip $ vi ~/.pip/pip.conf [global] trusted-host=mirrors.aliyun.com index-url=http: ...

  4. 解决IE浏览器“无法显示此网页”的问题

    诊断后提示:远程计算机或设备不接受连接 其他浏览器可以正常使用,QQ什么的也都正常,只有IE不能上网诊断提示:远程计算机或设备将不接受连接 ,网上找了好多方法都行不通.最后发现了这种方法,问题简单解决 ...

  5. PyQt5+python3+pycharm开发环境配置

    1.下载PyQt https://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.6/PyQt5-5.6-gpl-Py3.5-Qt5.6.0-x32- ...

  6. android app安全问题设置

    1.应用签名未校验风险:检测 App 程序启动时是否校验签名证书. 2.应用数据任意备份风险 Android 2.1 以上的系统可为 App 提供应用程序数据的备份和恢复功能,该 由 AndroidM ...

  7. CodeForces 670C Cinema

    简单题. 统计一下懂每种语言的人分别有几个,然后$O(n)$扫一遍电影就可以得到答案了. #pragma comment(linker, "/STACK:1024000000,1024000 ...

  8. HDU 5873 Football Games

    随便判了几个条件就过了,也不知道对不对的. 正解应该是: $[1].$${s_1} + {s_2} + {s_3} + ...... + {s_n} = n(n - 1)$ $[2].$${s_1} ...

  9. UIAlerView、UIActionSheet 和UIAlertViewController(点击注销确认按钮实现)

    - (IBAction)loginOut:(UIBarButtonItem *)sender { UIActionSheet *actionSheet = [[UIActionSheet alloc] ...

  10. 顶层const和底层const

    As we’ve seen, a pointer is an object that can point to a different object. As a result,we can talk ...