1025. PAT Ranking (25)


1025. PAT Ranking (25)


#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <iterator>
using namespace std;
class CA
{
public:
	struct position
	{
		int lastrank;
		int lastscore;
		int ranks;
		position(){lastscore=-1;ranks=1;lastrank=0;}
	};
	void run();
	map<int,map<string,int> > m;
};

void CA::run()
{
	int n,k,score,testees=0,lastscore=-1,lastrank,ranks=1;
	vector<position> pranks;
	string sid;
	cin>>n;
	int i;
	pranks.push_back(position());
	for(i=1;i<=n;i++)
	{
		pranks.push_back(position());
		cin>>k;
		while(k-->0)
		{
			testees++;
			cin>>sid>>score;
			m[score][sid]=i;
		}
	}
	cout<<testees<<endl;
	map<int,map<string,int > >::reverse_iterator im;
	for(im=m.rbegin();im!=m.rend();im++)
	{
		map<string,int>::iterator im1;
		for(im1=im->second.begin();im1!=im->second.end();im1++)
		{
			cout<<im1->first;
			if(im->first==lastscore)
			{
				cout<<" "<<lastrank;
			}
			else 
			{
				cout<<" "<<ranks;
				lastrank=ranks;
				lastscore=im->first;
			}
			ranks++;
			cout<<" "<<im1->second;
			if(im->first == pranks[im1->second].lastscore)
			{
				cout<<" "<<pranks[im1->second].lastrank;
			}
			else
			{
				cout<<" "<<pranks[im1->second].ranks;
				pranks[im1->second].lastrank=pranks[im1->second].ranks;
				pranks[im1->second].lastscore=im->first;
			}
			(pranks[im1->second].ranks)++;
			cout<<endl;
		}
	}
}


int main()
{
//	freopen("test.in","r",stdin);
	CA *a=new CA;
	a->run();
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值