PAT 1025

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

typedef struct{
	char rid[13];
	int score;
	int frank;
	int lrank;
	int location;
}testee;

vector<testee> list[300];

vector<testee> sumList;

//注意sort中使用的比较函数是bool,而且参数不是指针!
//int cmp(const void * a, const void * b){
//	testee ta = * ( (testee *)a);
//	testee tb = * ( (testee *)b);
bool cmp(testee ta, testee tb){
	if(ta.score != tb.score){
		return (ta.score > tb.score);
	}else{
		return (strcmp(ta.rid, tb.rid)<0);
	}
}

int main(){
	//freopen("in.txt","r",stdin);
	int N;
	scanf("%d",&N);

	int i,j;
	int count = 0;//testee总数
	//并列排名
	int locRank;
	int currScore;

	for(i=0; i<N; i++){
		int K;
		scanf("%d",&K);
		count += K;

		for(j=0; j<K; j++){
			testee tmp;
			scanf("%s %d",tmp.rid, &tmp.score);
			tmp.location = i + 1;
			list[i].push_back(tmp);			
		}
		//location排序
		sort(list[i].begin(), list[i].end(),cmp);
		
		//location名次
		locRank = 1;
		currScore = list[i][0].score;
		for(j=0; j<K; j++){
			if(list[i][j].score < currScore){
				list[i][j].lrank = j+1;
				locRank = j+1;
				currScore = list[i][j].score ;
			}else if(list[i][j].score == currScore){
				list[i][j].lrank = locRank;
			}
		}
	}

	
	//vectorappend使用insert
	for(i=0; i<N; i++){
		sumList.insert(sumList.end(),list[i].begin(), list[i].end());
	}
	printf("%d\n", sumList.size());

	sort(sumList.begin(), sumList.end(),cmp);

	locRank = 1;
	currScore = sumList[0].score;
	for(i=0; i<count; i++){
			if(sumList[i].score < currScore){
				sumList[i].frank = i+1;
				locRank = i+1;
				currScore = sumList[i].score ;
			}else if(sumList[i].score == currScore){
				sumList[i].frank = locRank;
			}
	}

	for(j=0; j<count; j++){
		printf("%s %d %d %d\n",sumList[j].rid, sumList[j].frank, sumList[j].location, sumList[j].lrank);
	}


	return 0;
}

一次A过,好感动oo>_<oo

转载于:https://my.oschina.net/kaneiqi/blog/204132

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值