题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1025

题目描述:

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

分析:

(1)对结构体排序并且合并。

(2)注意grade一样的情况下的处理。

(3)可以参考这篇:http://blog.csdn.net/realxuejin/article/details/10382159

参考代码:

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
using namespace std;
typedef struct student
{
string num;
int grade;
int final_rank;
int location_num;
int local_rank;
//注意以下这段的写法
bool operator > (const student& s)const
{
if(grade != s.grade)
return grade > s.grade;
else return num < s.num;
}
}student; #define max 30000
#define INF 0x6FFFFFFF
vector<student> v; int main()
{
int n,m;
int i,j;
cin>>n;
for(i=0; i<n; i++)
{
cin>>m;
vector<student> temp(m);
for(j=0; j<m; j++)
{
cin>>temp[j].num>>temp[j].grade;
temp[j].location_num = i+1;
}
sort(temp.begin(),temp.end(),greater<student>());
int nowGrade = INF;
int nowRank = 0;
for(j=0; j<m; j++)
{
////
//cout<<temp[j].num<<" "<<temp[j].location_num<<endl;
if(temp[j].grade == nowGrade)
temp[j].local_rank = nowRank;
else
{
temp[j].local_rank = j+1;
nowRank = j + 1;
nowGrade = temp[j].grade;
}
v.push_back(temp[j]);
}
}
// 处理global_rank
sort(v.begin(),v.end(),greater<student>()); //此处用到greater,头文件应该有#include<functional>
int nowGrade = INF;
int nowRank = 0;
cout<<v.size()<<endl;
for(i=0; i<v.size(); i++)
{
if(v[i].grade == nowGrade)
v[i].final_rank = nowRank;
else
{
nowRank = i+1;
v[i].final_rank = i+1;
nowGrade = v[i].grade;
}
cout<<v[i].num<<" "<<v[i].final_rank<<" "<<v[i].location_num<<" "<<v[i].local_rank<<endl;
} return 0;
}

【PAT】1025. PAT Ranking (25)的更多相关文章

  1. PAT 甲级 1025 PAT Ranking

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  2. PAT甲级——1025 PAT Ranking

    1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...

  3. PAT乙级 1025. 反转链表 (25)

    1025. 反转链表 (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一个常数K以及一个单链表L,请 ...

  4. 【RS】Local Collaborative Ranking - LCR: 局部协同排序

    [论文标题]Local Collaborative Ranking   (WWW '14 23rd WWW ) [论文作者]Joonseok [论文链接]Paper(11-pages // Doubl ...

  5. 【dfs】BZOJ1703-[Usaco2007 Mar]Ranking the Cows 奶牛排名

    [题目大意] 农夫约翰有N(1≤N≤1000)头奶牛,每一头奶牛都有一个确定的独一无二的正整数产奶率.约翰想要让这些奶牛按产奶率从高到低排序,约翰已经比较了M(1≤M≤10000)对奶牛的产奶率,但他 ...

  6. 【PAT甲级】1025 PAT Ranking (25 分)(结构体排序,MAP<string,int>映射)

    题意: 输入一个正整数N(N<=100),表示接下来有N组数据.每组数据先输入一个正整数M(M<=300),表示有300名考生,接下来M行每行输入一个考生的ID和分数,ID由13位整数组成 ...

  7. 【PAT】1028. List Sorting (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1028 题目描述: Excel can sort records according to an ...

  8. PAT 甲级1025 PAT Ranking (25 分)(结构体排序,第一次超时了,一次sort即可小技巧优化)

    题意: 给定一次PAT测试的成绩,要求输出考生的编号,总排名,考场编号以及考场排名. 分析: 题意很简单嘛,一开始上来就,一组组输入,一组组排序并记录组内排名,然后再来个总排序并算总排名,结果发现最后 ...

  9. 【PAT】1020 Tree Traversals (25)(25 分)

    1020 Tree Traversals (25)(25 分) Suppose that all the keys in a binary tree are distinct positive int ...

随机推荐

  1. LeetCode_Jump Game

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  2. 刺猬大作战(游戏引擎用Free Pascal写成,GUI用C++写成,使用SDL和Qt4)

    游戏特性[编辑] 游戏引擎用Free Pascal写成,GUI用C++写成,使用SDL和Qt4[2]. 0.9.12开始支持实时动态缩放游戏画面. 个性化[编辑] 刺猬大作战有着高度定制性 游戏模式: ...

  3. SQL Server 2008空间数据应用系列八:基于Bing Maps(Silverlight)的空间数据存储

    原文:SQL Server 2008空间数据应用系列八:基于Bing Maps(Silverlight)的空间数据存储 友情提示,您阅读本篇博文的先决条件如下: 1.本文示例基于Microsoft S ...

  4. JavaEE Tutorials (29) - Duke辅导案例研究示例

    29.1Duke辅导应用的设计和架构44529.2主界面447 29.2.1主界面中使用的Java持久化API实体447 29.2.2主界面中使用的企业bean448 29.2.3主界面中使用的Web ...

  5. 剑指offer-面试题15.链表中倒数第k个结点

    题目:输入一个链表,输出该链表的倒数第K个结点.为了符合大多数人的习惯,本题 从1开始计数,即链表的尾结点是倒数第1个节点.例如有一个链表有6个节点,从 头节点开始他们的值依次是1,2,3,4,5,6 ...

  6. 二分图带权最大独立集 网络流解决 hdu 1569

    方格取数(2) Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  7. java笔记之静态修饰附和单例设计模式

     第六天笔记 静态修饰符static: 一.static修饰成员变量: static用来修饰成员变量叫静态成员变量,没有static修饰的成员变量叫非静态成员变量 静态成员的访问方式: (1)   用 ...

  8. Windows Message Queue(优先队列)

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Windows Message Queue Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  9. 关于iOS多线程,你看我就够了

    在这篇文章中,我将为你整理一下 iOS 开发中几种多线程方案,以及其使用方法和注意事项.当然也会给出几种多线程的案例,在实际使用中感受它们的区别.还有一点需要说明的是,这篇文章将会使 用 Swift  ...

  10. 二、Mp3帧分析(标签帧)

    Mp3文件由帧组成,帧分成标签帧和数据帧,本文就Mp3文件的帧进行分析. 一.标签帧 MP3帧头中除了存储一些象private.copyright.original的简单音乐说明信息以外,没有考虑存放 ...