11723 집합
2019. 8. 31. 01:45ㆍ알고리즘/백준
int 변수 하나로 비트마스킹을 제어하는 문제
문제: https://www.acmicpc.net/problem/11723
깃허브주소: https://github.com/surinoel/boj/blob/master/11723.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
using namespace std; | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int n; | |
cin >> n; | |
int select = 0; | |
while (n--) { | |
string op; | |
int val; | |
cin >> op; | |
if (op == "add") { | |
cin >> val; | |
select |= (1 << val); | |
} | |
else if (op == "check") { | |
cin >> val; | |
if (select & (1 << val)) cout << 1 << '\n'; | |
else cout << 0 << '\n'; | |
} | |
else if (op == "remove") { | |
cin >> val; | |
select &= ~(1 << val); | |
} | |
else if (op == "toggle") { | |
cin >> val; | |
if (select & (1 << val)) { | |
select &= ~(1 << val); | |
} | |
else { | |
select |= (1 << val); | |
} | |
} | |
else if (op == "all") { | |
select = (1 << 21) - 1; | |
} | |
else if (op == "empty") { | |
select = 0; | |
} | |
} | |
return 0; | |
} |
'알고리즘 > 백준' 카테고리의 다른 글
1107 리모컨 (0) | 2019.08.31 |
---|---|
백준 N과 M 시리즈 코드 (0) | 2019.08.31 |
11660 구간 합 구하기 5 (0) | 2019.08.31 |
1759 암호 만들기 (0) | 2019.08.30 |
14500 테트로미노 (0) | 2019.08.29 |