Scroll indicator done
728x90

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


#include <iostream>
#include <string>
using namespace std;
/* 
비트 마스킹 문제
bit | (1 << n) : 원소 추가
bit & ~(1 << n) : 원소 제거
bit & (1 << n) : 원소 조회
bit ^ (1 << n) : 원소 토글
*/

int m, x, bit;
string cal;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> m;

	while (m--) {
		cin >> cal;
		if (cal == "add") {
			cin >> x;
			bit |= (1 << x);
		}
		else if (cal == "remove") {
			cin >> x;
			bit &= ~(1 << x);
		}
		else if (cal == "check") {
			cin >> x;
			if (bit & (1 << x)) cout << 1 << '\n';
			else cout << 0 << '\n';
		}
		else if (cal == "toggle") {
			cin >> x;
			bit ^= (1 << x);
		}
		else if (cal == "all") bit = (1 << 21) - 1;
		else if (cal == "empty") bit = 0;
	}
	return 0;
}
728x90

'BAEKJOON > C++' 카테고리의 다른 글

[B1764][듣보잡][C++]  (0) 2021.06.07
[B1620][나는야 포켓몬 마스터 이다솜][C++]  (0) 2021.06.07
[B1012][유기농 배추][C++]  (0) 2021.06.07
[B3040][백설공주와 일곱 난쟁이][C++]  (0) 2021.03.09
[B1041][주사위][C++]  (0) 2021.03.09