PAT ranking summary (25 points) (smart sorting + storage)

The computer programming ability test (Programming Ability Test, referred to as PAT) aims to objectively evaluate the candidate's algorithm design and program design realization ability through a unified online test and automatic evaluation method, scientifically evaluate computer programming talents, and select talents for enterprises Provide reference standards (website http://www.patest.cn).

Each test will be held at several different test centers at the same time, and each test center uses a local area network to generate the results of the test center. After the exam, the scores of each test center will be immediately summarized into a total ranking table.

Now please write a program to automatically merge the scores of each test center and generate a total ranking table.

Input format:
The first line of input gives a positive integer N (≤100), which represents the total number of test sites. Then the scores of N test sites are given in the format: the first line gives a positive integer K (≤300), which represents the total number of candidates at the test site; the next K lines, each line gives the information of 1 test taker, including the test number (by It is composed of 13 integers) and score (which is an integer in the interval [0,100]), separated by a space.

Output format:
First output the total number of candidates in the first line. Then output the summary ranking table, each candidate's information occupies a row, the order is: test number, final ranking, test site number, ranking in the test site. The test sites are numbered from 1 to N in the order given by the input. Candidates’ output must be output in the non-decreasing order of the final ranking. Candidates who obtain the same score should have the same ranking and output in the increasing order of the exam number.

Input sample:

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
I did this question for the second time. I saw someone else’s for the first time. This time I did it all by myself. The big framework was written very quickly. I changed the bug for a long time. I did this question for half an hour. . . The main reason is that there was an error in the ranking of the test center. Later, I wanted to sort the people in the test center directly after the entry of a test center, and then add it to the total ranking array stu, that's it, pay attention to empty the vector container! ! Regarding the ranking, it is the same as the previous time, and it can be directly equal to the previous ranking, but if it is not equal, the ranking at this time is the result of the previous accumulation (including the results tied), so each time you enter the loop, let the ranking ++ OK. So happy to make it

Insert picture description here

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

typedef struct{
    
    
	string id;//考号
	int score;//成绩
	int final;//最终排名
	int testid;//考点编号
	int test;//本考点排名
}Stu;

Stu stu[30005];//因为N<=100,K<=300,最终不会超过30000,我喜欢开大一点

bool cmp1(Stu s1,Stu s2){
    
    
	if(s1.score!=s2.score){
    
    
		return s1.score > s2.score;
	}
	else{
    
    
		return s1.id < s2.id;
	}
}

bool cmp2(Stu s1,Stu s2){
    
    
	if(s1.score!=s2.score)
		return s1.score > s2.score;
	else
		return s1.id < s2.id;
}

int main(){
    
    
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int n;
	cin >> n;
	int p = 0;
	vector<Stu> v;
	for(int i = 0;i<n;i++){
    
    
		v.clear();
		int k;
		Stu s;
		cin >> k;
		for(int j = 0;j<k;j++){
    
    
			cin >> s.id >> s.score;
			s.testid = i+1;
			v.push_back(s);
		}
		sort(v.begin(),v.end(),cmp1);
		int g = 1;
		v[0].test = 1;
		stu[p++] = v[0];
		for(int m = 1;m<v.size();m++){
    
    
			g++;
			if(v[m].score==v[m-1].score){
    
    
				v[m].test = v[m-1].test;
			}
			else{
    
    
				v[m].test = g;
			}
			stu[p++] = v[m];
		}
	}
	sort(stu,stu+p,cmp2);
	int grade = 1;
	stu[0].final = grade;
	for(int i = 1;i<p;i++){
    
    
		grade++;
		if(stu[i].score==stu[i-1].score){
    
    
			stu[i].final = stu[i-1].final;
			continue;
		}
		else{
    
    
			stu[i].final = grade;
		}
	}
	cout << p << endl;
	for(int i = 0;i<p;i++){
    
    
		cout << stu[i].id << " " << stu[i].final << " " << stu[i].testid << " " << stu[i].test << endl;
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45845039/article/details/108818612