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

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.

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 <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct testee{
	string id;
	int localid;
	int score;
	int localrank;
	int finalrank;
};
int sum=0;
vector<testee> data[100];
vector<testee> local;
bool sortbyScore(const testee t1,const testee t2){
	if(t1.score>t2.score){
		return true;
	}
	else if(t1.score==t2.score){
		return t1.id<t2.id;
	}
	return false;
}

int main(){
	int testcase;
	int num;
	string id;
	int grand;
	scanf("%d",&testcase);
	for(int i=1;i<=testcase;i++){
		scanf("%d",&num);
		sum+=num;
		while(num--){
		cin>>id>>grand;
		testee test;
		test.id=id;
		test.score=grand;
		test.localid=i;
		test.finalrank=0;
		test.localrank=0;
		data[i].push_back(test);
		}
	}
	for(int k=1;k<=testcase;k++){
		sort(data[k].begin(),data[k].end(),sortbyScore);
		data[k][0].localrank=1;
		for(int s=1;s<data[k].size();s++){
			if(data[k][s].score==data[k][s-1].score){
				data[k][s].localrank=data[k][s-1].localrank;
			}
			else{
				data[k][s].localrank=s+1;
			}
		}
		local.insert(local.end(),data[k].begin(),data[k].end());
	}

	sort(local.begin(),local.end(),sortbyScore);
	local[0].finalrank=1;
	for(int s=1;s<local.size();s++){
		if(local[s].score==local[s-1].score){
			local[s].finalrank=local[s-1].finalrank;
		}
		else{
			local[s].finalrank=s+1;
		}
	}
	cout<<sum<<endl;
	for(int l=0;l<local.size();l++){
		cout<<local[l].id<<" "<<local[l].finalrank<<" "<<local[l].localid<<" "<<local[l].localrank<<endl;
	}
	

	return 0;
}

But

 

 报了一个运行时错误。先记录到这里今天,时间有点完了,还要整理一下遇到的问题。

Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐