-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathZOJ1028(AC).cpp
74 lines (65 loc) · 1.07 KB
/
ZOJ1028(AC).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
64
65
66
67
68
69
70
71
72
73
74
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef struct st{
string id;
string name;
int grade;
}st;
bool comp1(const st &a, const st &b)
{
return a.id < b.id;
}
bool comp2(const st &a, const st &b)
{
if(a.name == b.name){
return a.id < b.id;
}else{
return a.name < b.name;
}
}
bool comp3(const st &a, const st &b)
{
if(a.grade == b.grade){
return a.id < b.id;
}else{
return a.grade < b.grade;
}
}
vector<st> v;
int n, c;
int main()
{
int i;
char s[20];
st t;
while(scanf("%d%d", &n, &c) == 2){
v.clear();
for(i = 0; i < n; ++i){
scanf("%s", s);
t.id = string(s);
scanf("%s", s);
t.name = string(s);
scanf("%d", &t.grade);
v.push_back(t);
}
switch(c){
case 1:
sort(v.begin(), v.end(), comp1);
break;
case 2:
sort(v.begin(), v.end(), comp2);
break;
case 3:
sort(v.begin(), v.end(), comp3);
break;
}
for(i = 0; i < n; ++i){
printf("%s %s %d\n", v[i].id.data(), v[i].name.data(), v[i].grade);
}
}
return 0;
}