A1025 PAT Ranking (25 分)

#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

struct  Student{
	char id[15];
	int score;
	int group;
	int rank_group;
	int rank_tol;
}stu[30010];

bool cmp(Student a, Student b){
	if(a.score != b.score) return a.score > b.score;
	else return strcmp(a.id, b.id) < 0;
}

int main(int argc, char** argv) {
	
	int n, k = 0;
	int tol = 0;
	
	cin >> n;
	
	for(int i = 0; i < n; i++){
		cin >> k;
		for(int j = 0; j < k; j++){
			cin >> stu[tol].id >> stu[tol].score;
			stu[tol].group = i+1;
			tol++;
		}
		sort(stu+tol-k, stu+tol, cmp);
		stu[tol-k].rank_group = 1;
		for(int j = tol-k+1; j < tol; j++){
			if(stu[j].score == stu[j-1].score){
				stu[j].rank_group = stu[j-1].rank_group ;
			}else{
				stu[j].rank_group = j-tol+k+1;
			}
		}
	}
		
	sort(stu, stu+tol, cmp);
	cout << tol << endl;

	stu[0].rank_tol = 1;
	
	for(int i = 0; i < tol; i++){
		if(i > 0 && stu[i].score != stu[i-1].score){
			stu[i].rank_tol = i + 1;
		} else if(i > 0 && stu[i].score == stu[i-1].score){
			stu[i].rank_tol = stu[i-1].rank_tol;
		}
		cout << stu[i].id << " " << stu[i].rank_tol << " " << stu[i].group << " " << stu[i].rank_group << endl;
	}
	
	return 0;
}
已标记关键词 清除标记
相关推荐
<p> <b><span style="background-color:#FFE500;">【超实用课程内容】</span></b> </p> <p> <br /> </p> <p> <br /> </p> <p> 本课程内容包含讲解<span>解读Nginx的基础知识,</span><span>解读Nginx的核心知识、带领学员进行</span>高并发环境下的Nginx性能优化实战,让学生能够快速将所学融合到企业应用中。 </p> <p> <br /> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <b><br /> </b> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <b><span style="background-color:#FFE500;">【课程如何观看?】</span></b> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> PC端:<a href="https://edu.csdn.net/course/detail/26277"><span id="__kindeditor_bookmark_start_21__"></span></a><a href="https://edu.csdn.net/course/detail/27216">https://edu.csdn.net/course/detail/27216</a> </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 移动端:CSDN 学院APP(注意不是CSDN APP哦) </p> <p style="font-family:Helvetica;color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 本课程为录播课,课程永久有效观看时长,大家可以抓紧时间学习后一起讨论哦~ </p> <p style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <br /> </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <strong><span style="background-color:#FFE500;">【学员专享增值服务】</span></strong> </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> <b>源码开放</b> </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 课件、课程案例代码完全开放给你,你可以根据所学知识,自行修改、优化 </p> <p class="ql-long-24357476" style="font-family:"color:#3A4151;font-size:14px;background-color:#FFFFFF;"> 下载方式:电脑登录<a href="https://edu.csdn.net/course/detail/26277"></a><a href="https://edu.csdn.net/course/detail/27216">https://edu.csdn.net/course/detail/27216</a>,播放页面右侧点击课件进行资料打包下载 </p> <p> <br /> </p> <p> <br /> </p> <p> <br /> </p>
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页