백준 11098번: 첼시를 도와줘!

danbibibi·2022년 4월 12일
0

문제

문제 바로가기> 백준 11098번: 첼시를 도와줘!

풀이

pair와 vecotr를 이용하고 정렬을 사용해서 간단하게 문제를 해결할 수 있다.

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, p, c;
    string name;
    cin >> n;
    while (n--){
        cin >> p;
        vector<pair<int, string>> v;
        for(int i=0; i<p; i++){
            cin >> c >> name;
            v.push_back({c, name});
        }
        sort(v.begin(), v.end());
        cout << v[p-1].second << '\n';
    }
}
profile
블로그 이전) https://danbibibi.tistory.com

0개의 댓글

관련 채용 정보