티스토리 뷰

백준

백준 소스코드 [C++] 11723 집합

Hani_Levenshtein 2021. 1. 5. 18:21

www.acmicpc.net/problem/11723

 

11723번: 집합

첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다.

www.acmicpc.net

백준 소스코드 [C++] 11723 집합

#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
#include <set>
#define all(v) v.begin(), v.end()
#define pii pair<int,int>
#define make_unique(v) v.erase(unique(v.begin(), v.end()), v.end())
typedef long long ll;
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	string s;
	cin >> n;
	set<int> SET,temp;
	for (int i = 1;i <= 20;i++)temp.insert(i);
	for (int i = 0;i < n;i++) {
		cin >> s;
		if (s == "add") {
			cin >> m;
			SET.insert(m);
		}

		else if (s == "check") {
			cin >> m;
			if (SET.find(m) == SET.end()) cout << "0" << '\n';
			else cout << "1" << '\n';
		}

		else if (s == "remove") {
			cin >> m;
			SET.erase(m);
		}

		else if (s == "toggle") {
			cin >> m;
			if (SET.find(m) == SET.end()) SET.insert(m);
			else SET.erase(m);

		}

		else if (s == "all") {
			SET = temp;
		}

		else if (s == "empty")
			SET.clear();

	}
	return 0;
}
댓글