-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy path1028_List Sorting (25).cpp
53 lines (47 loc) · 1.13 KB
/
1028_List Sorting (25).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
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
struct stu
{
char ID[10];
char name[10];
int grade;
}tmp;
vector<stu> Student;
int cmp1(const stu &a, const stu &b)
{
return strcmp(a.ID, b.ID) < 0;
}
int cmp2(const stu &a, const stu &b)
{
if(!strcmp(a.name, b.name))
return strcmp(a.ID, b.ID) < 0;
return strcmp(a.name, b.name) < 0;
}
int cmp3(const stu &a, const stu &b)
{
if(a.grade == b.grade)
return strcmp(a.ID, b.ID) < 0;
return a.grade < b.grade;
}
int main()
{
int n,select;
scanf("%d %d", &n, &select);
for(int i = 0; i < n; i++)
{
scanf("%s %s %d", tmp.ID, tmp.name, &tmp.grade);
Student.push_back(tmp);
}
switch(select)
{
case 1: sort(Student.begin(), Student.end(), cmp1); break;
case 2: sort(Student.begin(), Student.end(), cmp2); break;
case 3: sort(Student.begin(), Student.end(), cmp3); break;
}
for(vector<stu>::iterator iter = Student.begin(); iter != Student.end(); iter++)
printf("%s %s %d\n", iter->ID, iter->name, iter->grade);
return 0;
}