[HDU] [1862] EXCEL Sorting

Problem Description

Loading...

Problem Analysis

The first time you run into this kind of problem you might agonize over it for ages and rack up a pile of WAs…
Once you’ve got it figured out, though, it’s actually pretty easy.

cpp
 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;
}
This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...