PAT Ranking (排名)
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 (排名)的更多相关文章
- 1025 PAT Ranking[排序][一般]
1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer S ...
- 1141 PAT Ranking of Institutions[难]
1141 PAT Ranking of Institutions (25 分) After each PAT, the PAT Center will announce the ranking of ...
- pat1025. PAT Ranking (25)
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- PAT_A1141#PAT Ranking of Institutions
Source: PAT A1141 PAT Ranking of Institutions (25 分) Description: After each PAT, the PAT Center wil ...
- PAT_A1025#PAT Ranking
Source: PAT A1025 PAT Ranking Description: Programming Ability Test (PAT) is organized by the Colleg ...
- PAT甲级:1025 PAT Ranking (25分)
PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...
- PAT 甲级 1025 PAT Ranking
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- A1025 PAT Ranking (25)(25 分)
A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...
- 1025 PAT Ranking (25分)
1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...
随机推荐
- Advanced Installer
Advanced Installer是一款功能强大.可生成符合 MS Windows 认证的 Windows Installer 的 MSI 安装包制作工具,具有友好的图形用户界面,直观而且非常简单的 ...
- Asp.net封装js的类
using System; using System.Collections.Generic; using System.Text; using System.Web; using System.We ...
- python(1) - 列表和元组
列表(list) 列表是经常用到的一种数据类型,是一组有序的数据集合,可以将各种数据有序的存放在列表中,并且可以对其进行增删改查,以及遍历. 列表就是为了使变量能够存储更多的信息,比如我想存储一张购物 ...
- 怎么删除远程登录连接的ip
通过远程桌面可以登录到远程电脑上进行相应的操作,在登录过后会在本地电脑上留下登录过的IP以及登录用户名相关信息,可能会给远程的电脑带来安全隐患,下面介绍一下清除远程桌面历史记录的方法. 1.删除我的文 ...
- Eclipse遇到Initializing Java Tooling解决办法
可参考博客:http://liaojuncai.iteye.com/blog/1954113 打开Eclipse的时候莫名其妙的出现这个错误,进度条一直显示这个提示Initializing java ...
- [改善Java代码]避免在构造函数中初始化其他类
建议35: 避免在构造函数中初始化其他类 构造函数是一个类初始化必须执行的代码,它决定着类的初始化效率,如果构造函数比较复杂,而且还关联了其他类,则可能产生意想不到的问题,我们来看如下代码: publ ...
- 【线性结构上的动态规划】UVa 11584 - Partitioning by Palindromes
回文串问题.给出一个字符串,问最少可以划分为多少个字符串子串. 对于判断是否为回文串,对于不是很长的字符串,可以采取直接暴力,即从两边向中间收缩判断字符相等. bool is_pali(int l, ...
- ECharts地图详解 【转】
$(function() { // 路径配置 require.config({ paths : { // echarts: 'http://echarts.baidu.com/build/dist' ...
- 一个js排序
] d = d[a]; e = e[a]; d = ...
- android结束进程、退出application的方法
1.finish()方法 finish是Activity的类,仅仅针对Activity,当调用finish()时,只是将活动推向后台,并没有立即释放内存,活动的资源并没有被清理:调用finish()方 ...