Notice
Recent Posts
Recent Comments
Link
250x250
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Archives
Today
Total
관리 메뉴

피너클의 it공부방

백준 7785 회사에 있는 사람 (c++) : 피너클 본문

백준

백준 7785 회사에 있는 사람 (c++) : 피너클

피너클 2024. 11. 26. 14:05
728x90
반응형

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

그냥 set을 이용해 구현하는 문제다.

#include <iostream>
#include <set>
#include <string>

using namespace std;

int n;
set<string> s;
string a, b;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		if (b == "enter") {
			s.insert(a);
		}
		else {
			s.erase(a);
		}
	}
	set<string>::reverse_iterator iter;
	for (iter = s.rbegin(); iter != s.rend();  iter++) {
		cout << *iter << "\n";
	}
}

전체코드다.

 

들어와야 나갈수 있으니 erase전에 find를 하거나 하지는 않았다.

728x90
반응형
Comments