PAT1025. PAT Ranking

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

class Stu
{
public:
	char reg[14];
	int score;
	int location;
	int lrank;
};
bool comp(const Stu& a, const Stu& b)
{
	if(a.score > b.score)
		return true;
	else if(a.score == b.score)
	{
		return lexicographical_compare(a.reg,a.reg+13,b.reg,b.reg+13);
	}else{
		return false;
	}
}
Stu stus[300*100+10];
vector<Stu> res(300*100+10);
int main()
{
	int N;
	scanf("%d",&N);
	int curNum=0;
	vector<Stu>::iterator it;
	for(int location = 0;location<N;location++)
	{
		int K;
		scanf("%d",&K);
		
		for(int i=0;i<K;i++)
		{
			Stu * stu = &stus[location*300+i];
			scanf("%s %d",stu->reg,&stu->score);
			stu->location = location+1;
		}
		sort(&stus[location*300],&stus[location*300]+K,comp);
		int last = -1;
		int lastRank = -1;
		for(int i=0;i<K;i++)
		{
			Stu * stu = &stus[location*300+i];


			if(stu->score==last)
			{
				stu->lrank=lastRank;
			}else
			{
				stu->lrank = i+1;
			}
			lastRank = stu->lrank;
			last = stu->score;
		}
		if(location !=0)
		{
			//it = merge(res.begin(),it,&stus[location*300],&stus[location*300]+K,it,comp);
			it = merge(&stus[0],&stus[0]+curNum,&stus[location*300],&stus[location*300]+K,res.begin(),comp);
			copy(res.begin(),it,&stus[0]);
		}
		else
		{
			//it = copy(&stus[0],&stus[0]+K,res.begin());
		}
		curNum+=K;
	}
	int last=-1;
	int lastRank=-1;
	printf("%d\n",curNum);
	for(int i=0;i<curNum;i++)
	{
		Stu & stu = stus[i];
		int rank=0;
		if(stu.score==last)
		{
			rank=lastRank;
		}else
		{
			rank = i+1;
		}
		lastRank = rank;
		last = stu.score;
		printf("%s %d %d %d\n",stu.reg,rank,stu.location,stu.lrank);
	}
	return 0;
}



你可能感兴趣的:(PAT1025. PAT Ranking)