BOJ : https://www.acmicpc.net/problem/10825
구조체 operator 를 사용한 정렬을 해보고 싶은데 할줄 몰라서
일단 bool 함수를 만들어서 해결했다.
operator 함수 공부한 후 재포스팅해야겠다!
더보기
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
|
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;
struct stud {
string name;
int K, E, M;
}stu[100001];
bool cmp(stud& a, stud& b) {
if (a.K != b.K) return a.K > b.K;
else if (a.E != b.E) return a.E < b.E;
else if (a.M != b.M) return a.M > b.M;
else return a.name < b.name;
}
int main() {
ios::sync_with_stdio(false);
int N; cin >> N;
for (int i = 0; i < N; i++) {
cin >> stu[i].name >> stu[i].K >> stu[i].E >> stu[i].M;
}
sort(stu, stu + N, cmp);
for (int i = 0; i < N; i++) {
cout << stu[i].name << '\n';
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
'algorithm > BOJ' 카테고리의 다른 글
BOJ 11652번 카드 (0) | 2020.01.11 |
---|---|
BOJ 10989번 수 정렬하기 3 (0) | 2020.01.10 |
BOJ 10814번 나이순 정렬 (0) | 2020.01.10 |
BOJ 11651번 좌표 정렬하기2 (0) | 2020.01.10 |
BOJ 11650번 좌표 정렬하기 (0) | 2020.01.10 |