PAT 1025. PAT Ranking (25)

原创 2015年07月09日 10:03:20

题目说明:给出不同地区测试者的分数,计算出总排名和地区排名。

思路:简单的排序算法。先分别计算地区排名,然后合并所有vector,计算总排名。

代码:

#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

struct Testee{
	string ID;
	int score;
	int location;
	int localrank;
	int finalrank;
};
vector<Testee> tee[103]; 
vector<Testee> alltee;
int N,K;
int total=0;

bool cmp(const Testee &a,const Testee &b){
	if(a.score>b.score)
		return true;
	else if(a.score<b.score)
		return false;
	else{
		if(a.ID<b.ID)
			return true;
		else
			return false;
	}
}

int main(){
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>K;
		total+=K;
		for(int j=0;j<K;j++){
			Testee temp;
			cin>>temp.ID>>temp.score;
			temp.location=i;	
			tee[i].push_back(temp);
		}
	}	
	//计算localrank 
	for(int i=1;i<=N;i++){	
		sort(tee[i].begin(),tee[i].end(),cmp);	
		int lrank=1;
		tee[i][0].localrank=lrank;
		for(int j=1;j<tee[i].size();j++){
			lrank++;
			if(tee[i][j].score==tee[i][j-1].score){
				tee[i][j].localrank=tee[i][j-1].localrank;
			}
			else{
				tee[i][j].localrank=lrank;
			}
		}
		
	}
	//合并所有区 
	for(int i=0;i<=N;i++){
		alltee.insert(alltee.end(),tee[i].begin(),tee[i].end());
	}
	//计算finalrank 
	sort(alltee.begin(),alltee.end(),cmp);	
	int frank=1;
	alltee[0].finalrank=frank;
	for(int i=1;i<alltee.size();i++){
		frank++;
		if(alltee[i].score==alltee[i-1].score){			
			alltee[i].finalrank=alltee[i-1].finalrank;
		}
		else{
			alltee[i].finalrank=frank;
		}	
	}
	
	cout<<total<<endl;
	for(int i=0;i<alltee.size();i++){
		printf("%s %d %d %d\n",alltee[i].ID.c_str(),alltee[i].finalrank,
		alltee[i].location,alltee[i].localrank);
	}
	return 0;
}


1025. PAT Ranking (25)/YHF/2016/11/17

PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Prog...

1025. PAT Ranking (25)

考察结构体排序以及合并操作 #include #include #include #include #include #include #include #include using namespa...

1025. PAT Ranking (25)解析

PAT Ranking (25) Programming Ability Test (PAT) is organized by the College of Computer Science and...

【C++】PAT(advanced level)1025. PAT Ranking (25)*

1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CH...

PAT 1025. PAT Ranking (25)(分组排序再总体排序,计算rank)

官网1025. PAT Ranking (25)时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue...

PAT甲级.1025. PAT Ranking (25)

题目 Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of ...

1025. PAT Ranking (25)-PAT甲级

题目:Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of ...

PAT A1025. PAT Ranking (25)

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe...
  • jolivan
  • jolivan
  • 2017年01月08日 11:31
  • 86

1025. PAT Ranking (25) PAT 甲级

Problem Description Programming Ability Test (PAT) is organized by the College of Computer Science...
  • SY_Yu
  • SY_Yu
  • 2016年07月19日 00:16
  • 253

PAT 1025. PAT Ranking (25)

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:PAT 1025. PAT Ranking (25)
举报原因:
原因补充:

(最多只允许输入30个字)