※ 10825 국영수


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct { // 구조체를 정의합니다
string name;
int kor,eng,math;
} Student;
bool compare(const Student &a, const Student &b){ //비교 함수를 정의합니다
if(a.kor == b.kor){
if(a.eng == b.eng){
if(a.math == b.math){
return a.name < b.name;
}
return a.math > b.math;
}
return a.eng < b.eng;
}
return a.kor > b.kor;
}
vector<string> solution(int n,vector<string> name, vector<int> kor, vector<int> eng, vector<int> math){
vector<string> answer(n); // 정답을 담을 vector를 선언합니다
Student arr[n+1]; // Student 구조체 배열을 만듭니다
for(int i = 0; i < n; i++) arr[i] = {name[i],kor[i],eng[i],math[i]};
sort(arr,arr+n,compare); // 정렬합니다
for(int i = 0; i < n; i++) answer[i] = arr[i].name;
return answer;
}
int main()
{
int n;
cin>>n;
vector<string> name(n);
vector<int> kor(n);
vector<int> eng(n);
vector<int> math(n);
for(int i = 0; i < n; i++) cin>>name[i]>>kor[i]>>eng[i]>>math[i];
auto answer = solution(n,name, kor, eng, math);
for(auto i : answer) cout<<i<<'\n';
return 0;
}
'C++' 카테고리의 다른 글
[Algorithm] DFS 프로그래머스 92342 양궁대회 | C++ (0) | 2022.09.01 |
---|---|
[Algorithm] 스택 백준 10799번 쇠막대기 | C++ (0) | 2022.08.26 |
[Algorithm] 그리디 프로그래머스 42862번 체육복 | C++ (0) | 2022.08.22 |
[Algorithm] 백트래킹 백준 15649번 N과 M (1) | C++ (0) | 2022.08.01 |
[Algorithm] 브루트 포스 백준 2798번 블랙잭, 2231번 분해합 | C++ (0) | 2022.05.13 |
댓글