`
linest
  • 浏览: 149599 次
  • 性别: Icon_minigender_1
  • 来自: 内蒙古
社区版块
存档分类
最新评论

pat-1025 PAT Ranking

    博客分类:
  • pat
阅读更多
不同地点一起排序
先组内排序,再全局排序
将小组添加进全局

vector拼接
globallist.insert(globallist.end(),locallist.begin(),locallist.end()); 


#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;
	}


}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics