Algorithm/Problem Solving 2020. 5. 24. 00:06

(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)

 

문제 링크

- https://www.acmicpc.net/problem/10825

 

사용 알고리즘

- 정렬

 

풀이

- STL의 tuple 이용

 

소스 코드

- https://github.com/moomini/algorithm/blob/master/boj/10825.cpp

#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>
 
using namespace std;
 
struct Person {
    string name;
    int kor;
    int eng;
    int math;
};
 
bool cmp(const Person& u, const Person& v) {
    return make_tuple(-u.kor, u.eng, -u.math, u.name) < make_tuple(-v.kor, v.eng, -v.math, v.name);
}
 
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<Person> p(n);
    for (int i = 0; i < n; ++i) cin >> p[i].name >> p[i].kor >> p[i].eng >> p[i].math;
    sort(p.begin(), p.end(), cmp);
    for (int i = 0; i < n; ++i) cout << p[i].name << '\n';
    return 0;
}
cs

'Algorithm > Problem Solving' 카테고리의 다른 글

[BOJ/11652] 카드  (0) 2020.06.01
[BOJ/10989] 수 정렬하기 3  (0) 2020.05.26
[BOJ/10814] 나이순 정렬  (0) 2020.05.22
[BOJ/11651] 좌표 정렬하기 2  (0) 2020.05.21
[BOJ/11650] 좌표 정렬하기  (0) 2020.05.19
posted by DevMoomin
: