알고리즘
백준 13414번 수강신청 C++
영춘권의달인
2023. 1. 28. 11:07
https://www.acmicpc.net/problem/13414
13414번: 수강신청
입력 데이터는 표준 입력을 사용한다. 입력은 1개의 테스트 데이터로 구성된다. 입력의 첫 번째 줄에는 과목의 수강 가능 인원 K(1 ≤ K ≤ 100,000)와 학생들이 버튼을 클릭한 순서를 기록한 대기목
www.acmicpc.net
map<string, int> 로 입력받은 순서를 통해 우선순위를 정하고 원소들을 vector<pair<int,string>> 으로 옮겨서 우선순위를 기준으로 오름차순 정렬
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
struct Info {
int rank;
string str;
};
int k, l;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> k >> l;
map<string, int> m;
vector<pair<int,string>> v;
int rank = 0;
for (int i = 0; i < l; i++) {
string str;
cin >> str;
m[str] = rank++;
}
for (auto a : m) {
v.push_back({ a.second,a.first });
}
sort(v.begin(), v.end());
for (int i = 0; i < min(k,int(v.size())); i++) {
cout << v[i].second << "\n";
}
}