Notice
Recent Posts
Recent Comments
Link
«   2024/04   »
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
Archives
Today
Total
관리 메뉴

차근차근

[백준 10825] 국영수 본문

대학교/Algorithm

[백준 10825] 국영수

SWKo 2020. 4. 4. 00:36

0. 제목

  • 백준10825 국영수
  • BOJ 10825 국영수
  • C++ 10825 국영수

1. 문제

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

 

10825번: 국영수

첫째 줄에 도현이네 반의 학생의 수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 한 줄에 하나씩 각 학생의 이름, 국어, 영어, 수학 점수가 공백으로 구분해 주어진다. 점수는 1보다 크거나 같고, 100보다 작거나 같은 자연수이다. 이름은 알파벳 대소문자로 이루어진 문자열이고, 길이는 10자리를 넘지 않는다.

www.acmicpc.net


2. 풀이

  • 이름, 국어성적, 영어성적, 수학성적을 pair를 사용하여 묶어준다.
  • sort함수에서 쓰일 정렬 기준 함수인 comp를 주의해서 구현하면 된다.

3. 코드

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
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
pair<pair<stringint>pair<intint>> student[100001];
 
bool cmp(pair<pair<stringint>pair<intint>> a, pair<pair<stringint>pair<intint>> b){
        return true;
    else if(a.first.second == b.first.second){
        if(a.second.first < b.second.first)
            return true;
        else if(a.second.first == b.second.first){
            if(a.second.second > b.second.second)
                return true;
            else if(a.second.second == b.second.second)
                if(a.first.first < b.first.first)
                    return true;
        }
    }
    return false;
}
 
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int N;
    cin >> N;
    
    for(int i = 0; i < N; i++)
        cin >> student[i].first.first >> student[i].first.second >> student[i].second.first >> student[i].second.second;
    
    sort(student, student + N, cmp);
    for(int i = 0; i < N; i++)
        cout << student[i].first.first << '\n';
    
    return 0;
}
 
 

 

'대학교 > Algorithm' 카테고리의 다른 글

[백준 11652] 카드  (2) 2020.04.04
[백준 10989] 수 정렬하기 3  (0) 2020.04.04
[백준 1182] 부분수열의 합  (0) 2020.03.24
[백준 1987] 알파벳  (0) 2020.03.23
[백준 1759] 암호 만들기  (0) 2020.03.22
Comments