【杭电】[1236]排名

文章字数:174

问题描述

问题分析

也是WA了好多的一道题
思路还是计算分值之后排序
这里有个排序然后
对考号的排序是直接比较字符串就好了

 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
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct ks {
	char s[22];
	int q;
};
bool vs(ks A,ks B) {
	if(A.q==B.q)
		return strcmp(A.s,B.s)<0?1:0;
	else
		return A.q>B.q;
}
int main() {
	int N,M,G,t,p;
	int i,j,k;
	int a[12];
	struct ks person[1200],re[1200];
	while(scanf("%d",&N),N!=0) {
		scanf("%d %d",&M,&G);
		for(i=1; i<=M; i++)
			scanf("%d",&a[i]);
		for(k=i=0; i<N; i++) {
			scanf("%s %d",&person[i].s,&t);
			for(person[i].q=j=0; j<t; j++) {
				scanf("%d",&p);
				person[i].q+=a[p];
			}
			if(person[i].q>=G) {
				re[k++]=person[i];
			}
		}
		printf("%d\n",k);
		sort(re,re+k,vs);
		for(i=0; i<k; i++) {
			printf("%s %d\n",re[i].s,re[i].q);
		}
	}
	return 0;
}

该内容采用 CC BY-NC-SA 4.0 许可协议。

如果对您有帮助或存在意见建议,欢迎在下方评论交流。

加载中...