상세 컨텐츠

본문 제목

11723 : 집합

프로그래밍/백준

by whave 2022. 3. 14. 13:57

본문

#include <iostream>
#include<string>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int m;
	cin >> m;
	string order;
	int val,BIT=0;
	while(m--){
		cin>> order;
		//or연산자로 val번째 자리수를 1로 채운다. 
		if(order =="add"){
			cin >> val;
			BIT|=(1<<val);
		}
		//ex) 10000 & ~(10000) = 00000 
		else if(order=="remove"){
			cin >> val;
			BIT &= ~(1<<val);
		}
		else if(order == "check"){
			cin >> val;
			if(BIT & (1 << val))
				cout << 1 << '\n';
			else
				cout << 0 << '\n';
		}
		else if(order == "toggle"){
			cin >> val;
			BIT^=(1<<val);
		}
		else if(order == "all"){
			//ex) 10000 -1 =1111
			BIT = (1<<21)-1;
		}
		else if(order == "empty")
			BIT=0;
	}
	return 0;
}

'프로그래밍 > 백준' 카테고리의 다른 글

[C++] 11286 : 절댓값 힙  (0) 2022.04.14
[C언어/그리디] 1931 : 회의실 배정  (0) 2022.03.03
[C언어/그리디]1026 : 보물  (0) 2022.03.02
[C++/다익스트라] 1753 : 최단경로  (0) 2022.02.16
[C언어/DP] 9465 : 스티커  (0) 2022.02.12

관련글 더보기