PAT----A1025 PAT Ranking (25point(s))

A1025 PAT Ranking (25point(s))

题意

输入n个考场的学生信息,要求排序输出全局排名,考场排名等信息。

思路

考场排名可以使用数组解决。
Sample Input:

2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85

Sample Output:

9
1234567890005 1 1 1
1234567890014 1 2 1
1234567890001 3 1 2
1234567890003 3 1 2
1234567890004 5 1 4
1234567890012 5 2 2
1234567890002 7 1 5
1234567890013 8 2 3
1234567890011 9 2 4
#include"bits/stdc++.h"
using namespace std;
struct Node{
	string id;
	int g;
	int locate;
	int rank;
	int locateRank;
};
int main(){
	freopen("input.txt","r",stdin);
	int n; cin >> n;
	vector<Node*> nodes;
	for(int i=0;i<n;i++){
		int k; scanf("%d",&k);
		for(int j=0;j<k;j++){
			string s; int g;
			cin >> s >> g;
			Node *p = new Node{s,g,i+1};
			nodes.push_back(p);
		}
	}
	sort(nodes.begin(),nodes.end(),[](Node *t1,Node *t2){
		if(t1->g == t2->g)
			return t1->id < t2->id;
		return t1->g > t2->g;
	});
	vector<Node*> locates[n+1];
	for(int i=0;i<nodes.size();i++){
		Node *p = nodes[i];
		if(i){
			p->rank = p->g == nodes[i-1]->g ? nodes[i-1]->rank : i+1;
		}else
			p->rank = i+1;
		vector<Node*>&temp =locates[p->locate];
		p->locateRank = temp.size() + 1;
		if(!temp.empty() && p->g ==temp.back()->g )
			p->locateRank = temp.back()->locateRank;
		temp.push_back(p);	
		cout << p->id;
		printf(" %d %d %d\n",p->rank,p->locate,p->locateRank);
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值