-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList_Sorting.cpp
67 lines (59 loc) · 1.32 KB
/
List_Sorting.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
#include <iostream>
#include <string>
#include<algorithm>
struct record
{
std::string s[3];
};
record students[100010];
int n, c;
bool cmp(record a,record b)
{
if(a.s[c-1]==b.s[c-1])
return a.s[0] < b.s[0];
return a.s[c - 1] < b.s[c - 1];
}
int main()
{
scanf("%d %d", &n, &c);
for (int i = 0; i < n; i++)
{
scanf("%s %s %s",students[i].s[0].c_str(),students[i].s[1].c_str(),students[i].s[2].c_str());
}
std::sort(students, students + n, cmp);
for (int i = 0; i < n; i++)
{
printf("%s %s %s\n", students[i].s[0].c_str(), students[i].s[1].c_str(), students[i].s[2].c_str());
}
return 0;
}
/* #include <iostream>
#include <string>
#include<algorithm>
struct record
{
std::string s[3];
};
record students[100010];
int n, c;
bool cmp(record a,record b)
{
if(a.s[c-1]==b.s[c-1])
return a.s[0] < b.s[0];
return a.s[c - 1] < b.s[c - 1];
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin >> n >> c;
for (int i = 0; i < n; i++)
{
std::cin >> students[i].s[0] >> students[i].s[1] >> students[i].s[2];
}
std::sort(students, students + n, cmp);
for (int i = 0; i < n; i++)
{
std::cout << students[i].s[0] << " " << students[i].s[1] << " " << students[i].s[2] << std::endl;
}
return 0;
} */