-
Notifications
You must be signed in to change notification settings - Fork 0
/
1028.cpp
63 lines (54 loc) · 921 Bytes
/
1028.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
struct Rec{
char id[10];
char name[10];
int grade;
}rec[100010];
bool cmp1(Rec a, Rec b){
return strcmp(a.id, b.id) < 0;
}
bool cmp2(Rec a, Rec b){
if(strcmp(a.name, b.name) < 0){
return 1;
}
else if(strcmp(a.id, b.id) < 0 && strcmp(a.name, b.name) == 0){
return 1;
}
else{
return 0;
}
}
bool cmp3(Rec a, Rec b){
if(a.grade < b.grade){
return 1;
}
else if(strcmp(a.id, b.id) < 0 && a.grade == b.grade){
return 1;
}
else{
return 0;
}
}
int main(){
int N, C;
scanf("%d %d", &N, &C);
for(int i = 0; i < N; i++){
scanf("%s %s %d", rec[i].id, rec[i].name, &rec[i].grade);
}
if(C == 1){
sort(rec, rec+N, cmp1);
}
else if(C == 2){
sort(rec, rec+N, cmp2);
}
else{
sort(rec, rec+N, cmp3);
}
for(int i = 0; i<N; i++){
printf("%s %s %d\n", rec[i].id, rec[i].name, rec[i].grade);
}
return 0;
}