티스토리 뷰
비트 연산의 기본 문제다
add=> or
remove => & 0
check => & 1
toggle => ^ 1
all => (1<<n) -1
empty => 0
소스코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <iostream> #include <string> using namespace std; int n, m,x; char s[11]; int main() { scanf(" %d", &m); for (int i = 0; i < m; i++) { scanf(" %s", &s); scanf(" %d", &x); if (s[0]=='a' && s[1]=='d') n |= (1 << x); else if (s[0] == 'r') n &= ~(1 << x); else if (s[0] == 'c') printf("%d\n", (n&(1 << x)) ==0? 0: 1); else if (s[0] == 't') n ^=(1<<x); else if (s[0] == 'a' && s[1] == 'l') n = (1 << 21) - 1; else n = 0; } } | cs |
'알고리즘 > BOJ' 카테고리의 다른 글
[백준] 6603 로또 (0) | 2018.07.05 |
---|---|
[백준] 13701 중복 제거 (1) | 2018.07.05 |
[백준] 9328 열쇠 (0) | 2018.07.04 |
[백준] 5427 불 (0) | 2018.07.04 |
[백준] 2146 다리 만들기 (4) | 2018.07.04 |
댓글