[백준] 13414번

Jeanine·2022년 3월 23일
0

baekjoon

목록 보기
30/120
post-thumbnail
post-custom-banner

💻 C++ 기반

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

#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int K, L;
    cin >> K >> L;

    unordered_map<string, int> students;
    for (int i = 0; i < L; i++)
    {
        string student;
        cin >> student;
        students[student] = i;
    }

    vector<pair<int, string> > v;
    for (unordered_map<string, int>::iterator idx = students.begin(); idx != students.end(); idx++)
    {
        v.push_back(make_pair(idx->second, idx->first));
    }
    sort(v.begin(), v.end());

    if (v.size() < K)
    {
        vector<pair<int, string> >::iterator i;
        for (i = v.begin(); i != v.end(); i++)
        {
            cout << (*i).second << '\n';
        }
    }
    else
    {
        for (int i = 0; i < K; i++)
        {
            cout << v[i].second << '\n';
        }
    }

    return 0;
}
profile
Grow up everyday
post-custom-banner

0개의 댓글