본문 바로가기

알고리즘/BOJ

10825번

10825번 - 국영수


operator 재정의를 통해서 문제를 해결할 수 있었다.


원래 operator 재정의를 잘 몰랐었는데, 이 문제와 그 외 슬랙에 질문을 통해서 사용할 줄 알게 됐다.


슬랙에 operator  매개변수에 const 를 꼭 사용해야 하는지 물었는데, 갓님들의 답변




<정답 코드>


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
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
const int INF = 987654321;
typedef struct {
    int kor;
    int eng;
    int math;
    string name;
}person;
 
bool operator<(const person &a, const person &b)
{
    if (a.kor > b.kor)
    {
        return true;
    }
    else if (a.kor == b.kor)
    {
        if (a.eng < b.eng)
        {
            return true;
        }
        else if (a.eng == b.eng)
        {
            if (a.math > b.math)
            {
                return true;
            }
            else if (a.math == b.math)
            {
                if (a.name < b.name)
                {
                    return true;
                }
            }
        }
    }
 
    return false;
}
int main()
{
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<person> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i].name >> v[i].kor >> v[i].eng >> v[i].math;
    }
    sort(v.begin(), v.end());
 
    for (int i = 0; i < n; i++)
    {
        cout << v[i].name << "\n";
    }
 
    return 0;
}
cs


반응형

'알고리즘 > BOJ' 카테고리의 다른 글

2484번  (0) 2018.03.25
3665번(다시풀기)  (0) 2018.03.25
5635번  (0) 2018.03.24
11066번(다시풀기)  (0) 2018.03.24
14495번  (0) 2018.03.23