Online Judge/백준
[백준][C++] 7785: 회사에 있는 사람
vince joe
2020. 7. 6. 22:15
문제 링크: https://www.acmicpc.net/problem/7785
문제 푸는 여러 방법이 있겠는데, std::set
을 써보겠습니다. std::unordered_set
(hash set)이 좀 더 빠를 것 같지만 출력을 정렬해서 해야돼서 귀찮으니 그냥 set을 썼습니다. 어짜피 hash set을 쓰면출력 전에 한번 정렬해야되니 걸리는 시간은 비슷합니다.
그냥 set에다가 넣었다 뺐다 해주면 됩니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
set<string> us;
int n;
cin >> n;
while (n--) {
string name, action;
cin >> name >> action;
if (action == "enter")
us.insert(name);
else
us.erase(name);
}
for (auto rit = us.rbegin(); rit != us.rend(); ++rit)
cout << *rit << '\n';
return 0;
}
반응형