#include <iostream>
#include <set>
using namespace std;
struct myOrder
{
bool operator() (const std::string& left, const std::string& right) const
{
return left > right;
}
};
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
cin >> N;
std::string name;
std::string enter_or_leave;
std::set<std::string, myOrder> people_set;
for(int i=0; i<N; i++)
{
cin >> name >> enter_or_leave;
if(enter_or_leave == "enter") people_set.insert(name);
else people_set.erase(name);
}
for(auto person : people_set)
{
cout << person << '\n';
}
}
직접 struct 및 operator를 구현하여 오버라이딩 하면 된다.
set 선언 할 때 std::set<type, 구현한 operator> 형식으로 사용
'BOJ Review > C++ Techniques' 카테고리의 다른 글
| [C++] std::istringstream (0) | 2023.08.20 |
|---|---|
| [C++] 정렬된 vector에서 특정 요소의 위치 찾기 (0) | 2023.08.19 |
| [C++] 중복된 요소 제거하기 (0) | 2023.08.19 |
| [C++] sync_with_stdio (0) | 2023.08.19 |