---
title: "pat-1025 PAT Ranking"
author: "linest"
date: "2012-02-19T15:45:07Z"
tags: []
categories: ["编程语言"]
slug: "pat-1025-pat-ranking"
draft: false
lastmod: "2012-02-19T15:46:09Z"
id: 1412135
url: "https://linest.iteye.com/blog/1412135"
---

不同地点一起排序
先组内排序，再全局排序 
将小组添加进全局

vector拼接
globallist.insert(globallist.end(),locallist.begin(),locallist.end());  



```c++

#include<iostream>
using namespace std;
#include<vector>
#include<string>
#include<algorithm>

struct Score
{
	string id;
	int score;
	int local;
	int global;
	int location;
};

bool sortByScore(Score a,Score b)
{
	if(a.score != b.score)
		return  a.score > b.score;
	else
		return a.id < b.id;
}


int main()
{
	vector<Score> globallist;
	vector<Score> locallist;

	int N;
	int K;

	cin>>N;
	for(int n=1;n<=N;n++)
	{
		cin>>K;
		while(K--)
		{
			Score s;
			cin >> s.id;
			cin >> s.score;
			s.location = n;
			locallist.push_back(s);
		}

		sort(locallist.begin(),locallist.end(),sortByScore);
		//rank
		for(int i=0;i<locallist.size();i++)
		{
			if(i!=0 && locallist[i].score == locallist[i-1].score)
				locallist[i].local = locallist[i-1].local;
			else
				locallist[i].local = i+1;
		}
		//add
		globallist.insert(globallist.end(),locallist.begin(),locallist.end());
		locallist.clear();
	}

	//rank
	cout<<globallist.size()<<endl;
	sort(globallist.begin(),globallist.end(),sortByScore);
	for(int i=0;i<globallist.size();i++)
	{
		if(i!=0 && globallist[i].score == globallist[i-1].score)
			globallist[i].global = globallist[i-1].global;
		else
			globallist[i].global = i+1;
		cout<<globallist[i].id<<" "<<globallist[i].global<<" "<<globallist[i].location<<" "<<globallist[i].local<<endl;
	}


}



```