[백준] 10825번 국영수 / C++
#문제
#풀이
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<pair<string, pair<int, pair<int, int>>>> vec;
bool compair(pair<string, pair<int, pair<int, int>>> p1, pair<string, pair<int, pair<int, int>>> p2)
{
if (p1.second.first == p2.second.first)
{
if (p1.second.second.first == p2.second.second.first)
{
if (p1.second.second.second == p2.second.second.second)
{
return p1.first < p2.first;
}
return p1.second.second.second > p2.second.second.second;
}
return p1.second.second.first < p2.second.second.first;
}
return p1.second.first > p2.second.first;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i < n; ++i)
{
string name;
int x, y, z;
cin >> name >> x >> y >> z;
vec.push_back(make_pair(name, make_pair(x, make_pair(y, z))));
}
sort(vec.begin(), vec.end(), compair);
for (int i = 0; i < n; ++i)
{
cout << vec[i].first << '\n';
}
return 0;
}
#정리
sort 함수의 compair 함수를 사용하여 풀 수 있는 문제. 조건 안에 오름차순, 내림차순 정렬이 섞여 있기 때문에 문제를 잘 읽어봐야 했다. 모든 조건이 내림차순 정렬인줄 알고 몇 번을 검토했다.
Enjoy Reading This Article?
Here are some more articles you might like to read next: