문제풀이(Problem Solving)

백준, BOJ, 10825번, 국영수 : C++ [CPP] ★

게임이 더 좋아 2022. 2. 8. 20:05
반응형
728x170

어렵지 않다.

그냥 풀면되는데..

Compare 함수에 익숙하지 않다면 어려울 수도 있다.

 

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

 


 

#맞은 풀이

#include <bits/stdc++.h>

using namespace std;


//구조체
struct Student{
    string name;
    int korean;
    int english;
    int math;
};

//구조체 벡터
vector<Student> vec;

int  N;
//감소하는 순 (참조자로 받는다 -> 시간 단축)
bool comp(const Student &stA, const Student &stB){
    
    //가장 밑에 첫번째 기준을 써놓고
    if(stA.korean == stB.korean){
        if(stA.english == stB.english){
            if(stA.math == stB.math){
                //마지막 기준
                return stA.name < stB.name;
            }
            //세 번째 기준
            return stA.math > stB.math;  
        }
        //두 번째 기준
        return stA.english < stB.english;
    }
    //첫 번째 기준
    return stA.korean > stB.korean;
}

int main(){
    cin >> N;
    for(int i = 0; i<N; i++){
        Student a;
        cin >> a.name >> a.korean >> a.english >> a.math;
        vec.push_back(a);
    }
    
    sort(vec.begin(), vec.end(), comp);
    
    
    for(auto x : vec){
        cout << x.name << '\n';
    }
    return 0;
}

 

어렵다기보다는.. 그냥 시간이 걸린다.

 

반응형
그리드형