【杭电】[1862]EXCEL排序

文章字数:165

问题描述

问题分析

第一次接触到这种题可能会纠结好久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
42
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct stu {
	int x;
	char s[22];
	int a;
}person[100200];
bool vsx(stu A,stu B) {
	return A.x<B.x;
}
bool vss(stu A,stu B) {
	if(strcmp(A.s,B.s)!=0)
		return strcmp(A.s,B.s)<0;
	else
		return A.x<B.x;
}
bool vsa(stu A,stu B) {
	if(A.a!=B.a)
		return A.a<B.a;
	else
		return A.x<B.x;
}
int main() {
	int N,C;
	int j,i=0;
	while(scanf("%d %d",&N,&C),N!=0) {
		for(j=0; j<N; j++)
			scanf("%d %s %d",&person[j].x,&person[j].s,&person[j].a);
		if(C==1)
			sort(person,person+N,vsx);
		else if(C==2)
			sort(person,person+N,vss);
		else
			sort(person,person+N,vsa);
		printf("Case %d:\n",++i);
		for(j=0; j<N; j++)
			printf("%06d %s %d\n",person[j].x,person[j].s,person[j].a);
	}
	return 0;
}

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

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

加载中...