• 1025 PAT Ranking


    1025 PAT Ranking

    0、题目

    Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.

    Input Specification:

    Each input file contains one test case. For each case, the first line contains a positive number N (≤100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤300), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.

    Output Specification:

    For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:

    registration_number final_rank location_number local_rank
    
    • 1

    The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.

    1、大致题意

    n 个考场,每个考场有若干数量的学生,给出每个考场中考生的编号和分数,要求算排名,输出所有考生的编号、排名、考场号、考场内排名

    2、基本思路

    简单题

    3、解题过程

    3.1 坑点 - 测试点4(22/25)

    ID有类似 000003 这种形式的,如果是数字类型就容易输出错误,前导零别忘了。

    #include
    #include
    int n,k[105],cnt;
    struct Student {
    	long long num;
    	int score;
    	int final_rank,location_number,local_rank;
    	bool operator >(const Student &a)const {
    		if(score!=a.score) {
    			return score>a.score;
    		} else {
    			return num<a.num;
    		}
    	};
    } stu[10000005];
    using namespace std;
    int main() {
    	cin>>n;
    	cnt=0;
    	for(int i=1; i<=n; i++) {
    		cin>>k[i];
    		for(int j=1; j<=k[i]; j++) {
    			cin>>stu[cnt+j].num>>stu[cnt+j].score;
    		}
    		sort(stu+cnt+1,stu+cnt+k[i]+1,greater<Student>());
    		stu[cnt+1].location_number=i;
    		stu[cnt+1].local_rank=1;
    		for(int j=2; j<=k[i]; j++) {
    			if(stu[cnt+j].score==stu[cnt+j-1].score) {
    				stu[cnt+j].local_rank=stu[cnt+j-1].local_rank;
    			} else {
    				stu[cnt+j].local_rank=j;
    			}
    			stu[cnt+j].location_number=i;
    		}
    		cnt+=k[i];
    	}
    	sort(stu+1,stu+cnt+1,greater<Student>());
    	stu[1].final_rank=1;
    	for(int i=2; i<=cnt; i++) {
    		if(stu[i].score==stu[i-1].score) {
    			stu[i].final_rank=stu[i-1].final_rank;
    		} else {
    			stu[i].final_rank=i;
    		}
    	}
    	cout<<cnt<<endl;
    //	1234567890005 1 1 1
    	for(int i=1; i<=cnt; i++) {
    		cout<<stu[i].num<<" "<<stu[i].final_rank<<" "<<stu[i].location_number<<" "<<stu[i].local_rank<<endl;
    	}
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53

    在这里插入图片描述

    3.2 AC代码

    #include
    #include
    #include
    int n,k[105],cnt;
    struct Student {
    	long long num;
    	int score;
    	int final_rank,location_number,local_rank;
    	bool operator >(const Student &a)const {
    		if(score!=a.score) {
    			return score>a.score;
    		} else {
    			return num<a.num;
    		}
    	};
    } stu[10000005];
    using namespace std;
    int main() {
    	cin>>n;
    	cnt=0;
    	for(int i=1; i<=n; i++) {
    		cin>>k[i];
    		for(int j=1; j<=k[i]; j++) {
    			cin>>stu[cnt+j].num>>stu[cnt+j].score;
    		}
    		sort(stu+cnt+1,stu+cnt+k[i]+1,greater<Student>());
    		stu[cnt+1].location_number=i;
    		stu[cnt+1].local_rank=1;
    		for(int j=2; j<=k[i]; j++) {
    			if(stu[cnt+j].score==stu[cnt+j-1].score) {
    				stu[cnt+j].local_rank=stu[cnt+j-1].local_rank;
    			} else {
    				stu[cnt+j].local_rank=j;
    			}
    			stu[cnt+j].location_number=i;
    		}
    		cnt+=k[i];
    	}
    	sort(stu+1,stu+cnt+1,greater<Student>());
    	stu[1].final_rank=1;
    	for(int i=2; i<=cnt; i++) {
    		if(stu[i].score==stu[i-1].score) {
    			stu[i].final_rank=stu[i-1].final_rank;
    		} else {
    			stu[i].final_rank=i;
    		}
    	}
    	cout<<cnt<<endl;
    	for(int i=1; i<=cnt; i++) {
    		cout<<setfill('0')<<setw(13)<<stu[i].num<<" "<<stu[i].final_rank<<" "<<stu[i].location_number<<" "<<stu[i].local_rank<<endl;
    	}
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53

    在这里插入图片描述

  • 相关阅读:
    网络协议:TCP/IP协议
    springboot发送邮件
    Ribbon
    西门子S7协议介绍
    《虚拟现实技术》教学上机实验报告
    阿里云云安全中心详细介绍(原态势感知)功能价格说明
    android使用真随机算法模拟彩票号码生成器
    数据结构 - 数组
    Node.js 使用 officecrypto-tool 读取加密的 Excel (xls, xlsx) 和 Word( docx)文档
    入行测试6年了,从月薪3000到30000,浅谈我的自动化测试进阶之路...
  • 原文地址:https://blog.csdn.net/qq_46371399/article/details/126413897