HDU-1236 ranking (structure sort

Problem Description
Although there is a real-time Ranklist for the computer test today, the ranking above is only based on the number of completed questions, without considering
the value of each question, so it is not the final ranking. Given the admission score line, please write a program to find the
candidates who passed the score line last , and print their scores in descending order.

Input The
test input contains information about several exams. The first line of each test information gives the number of candidates N (0 <N
<1000 ), the number of test questions M (0 <M <= 10 ), and the score line (positive integer) G; the second line gives the number of questions 1 to The positive integer score of question M; the following N lines, each line gives a
candidate's admission ticket number (a string of no more than 20), the total number m of questions that the student has solved, and the question number of the m question
(The question number is from 1 to M).
When the number of candidates read is 0, the input is over and the exam will not be processed.

Output
For each exam, first output the number n of candidates who are not lower than the score line on the first line, and then
output the test number and score of the online candidates according to the score from high to low, separated by a space. If there are multiple candidates with the same score, they will be
output in ascending order of their exam numbers.

Sample Input
4 5 25
10 10 12 13 15
CS004 3 5 1 3
CS003 5 2 4 1 3 5
CS002 2 1 2
CS001 3 2 3 5
1 2 40
10 30
CS001 1 2
2 3 20
10 10 10
CS000000000000000001 0
CS000000000000000002 2 1 2
0

Sample Output
3
CS003 60
CS001 37
CS004 37
0
1
CS000000000000000002 20

Hint

Huge input, scanf is recommended.

Source
Zhejiang University Computer Postgraduate Re-examination Computer Exam-2005

Recommend
JGShining | We have carefully selected several similar problems for you: 1234 1231 1228 1237 1232

#include<bits/stdc++.h>
using namespace std;
int num [1009];
struct node {
    
    
	char s[50];
	int sum;
} ;
bool cmp(node a, node b) {
    
    
	if(a.sum>b.sum)return a.sum > b.sum;
	if(a.sum==b.sum&&strcmp(a.s,b.s)<0)return true;
	return false;
	
}
int main() {
    
    
	node t[1009];
	int n, m, g;
	while (scanf("%d", &n)) {
    
    
		if (n == 0)break;
		int total = 0;
		scanf("%d%d", &m, &g);
		memset(num, 0, sizeof(num));
	//	memset(t, 0, sizeof(node));
		for (int i = 0; i < m; i++)scanf("%d", &num[i]);
		for (int i = 0; i < n; i++) {
    
    
			scanf("%s", &t[i].s);
			int nn, x, sum = 0;
			scanf("%d", &nn);
			for (int j = 0; j < nn; j++) {
    
    
				scanf("%d", &x);
				sum += num[x - 1];
			}
			if (sum >= g) {
    
    
				strcpy(t[total].s, t[i].s);
				t[total].sum = sum;
				total++;
			}

		}
		sort(t, t + total, cmp);
		printf("%d\n", total);
		for (int i = 0; i < total; i++)printf("%s %d\n", t[i].s, t[i].sum);
	}

	return 0;
}

Guess you like

Origin blog.csdn.net/Minelois/article/details/113208322