博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
浙大pat 1025题解
阅读量:4322 次
发布时间:2019-06-06

本文共 2831 字,大约阅读时间需要 9 分钟。

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:
251234567890001 951234567890005 1001234567890003 951234567890002 771234567890004 8541234567890013 651234567890011 251234567890014 1001234567890012 85
Sample Output:
91234567890005 1 1 11234567890014 1 2 11234567890001 3 1 21234567890003 3 1 21234567890004 5 1 41234567890012 5 2 21234567890002 7 1 51234567890013 8 2 31234567890011 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;

}

转载于:https://www.cnblogs.com/luxiao/p/pat1025.html

你可能感兴趣的文章
linux 命令(9) top
查看>>
Android消息处理(一)进程内通信
查看>>
利用office2010 word2010生成目录
查看>>
[ffmpeg 扩展第三方库编译系列] 关于libvpx mingw32编译问题
查看>>
虚拟现实技术对人类是福还是祸?
查看>>
P3106 GPS的决斗
查看>>
hdoj1164
查看>>
简单工厂模式
查看>>
Using关键字的用法
查看>>
标准C程序设计七---60
查看>>
[Silverlight入门系列]使用MVVM模式(4):Prism的NotificationObject自动实现INotifyPropertyChanged接口...
查看>>
工作用工具
查看>>
字符串操作(字符数统计及字符串反转)
查看>>
TexturePacker license Key免费获取方式
查看>>
Android APK反编译
查看>>
两年面试你心得
查看>>
GBK编码相关
查看>>
hdu 1301 Jungle Roads (最小生成树)
查看>>
Java 多态 构造方法
查看>>
ActiveMQ-持久化存储方式
查看>>