자라는 개발자/문제풀이

백준 c++ 11292 키 큰 사람

자란다 2022. 6. 7. 16:01
728x90
반응형

11292 키 큰 사람


문제풀이

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void fast_io(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
bool cmp(pair<double, string> a, pair<double, string> b)
{
    return a.first > b.first;
}
vector<pair<double, string>> v;
int main(void)
{
    fast_io();
    int n;
    while(true)
    {
        cin >> n;
        if(!n)
            break;
        for (int i = 0;i<n;i++)
        {
            double dou;
            string str;
            cin >> str >> dou;
            v.push_back({dou, str});
        }
        stable_sort(v.begin(), v.end(),cmp);
        for (int i = 0; i < n;i++)
            if(v[0].first == v[i].first)
                cout << v[i].second << " ";
        cout << "\n";
        v.clear();
    }
}

tuple 을 이용해서 순서를 유지하려했는데 stable_sort()를 알게되어 순서 유지후 출력했다.

728x90
반응형

'자라는 개발자 > 문제풀이' 카테고리의 다른 글

백준 c++ 3135 라디오  (0) 2022.06.25
백준 c++ 2828 사과 담기 게임  (0) 2022.06.24
백준 c++ 16212 정열적인 정렬  (0) 2022.06.06
백준 c++ 20291 파일정리  (0) 2022.06.05
백준 c++ 17254 키보드이벤트  (0) 2022.06.02