[백준 11723번 C/C++] 집합
[백준 11723번 C/C++] 집합

https://www.acmicpc.net/problem/11723
해결전략
비트마스킹 Bitmasking
정답 코드
#include <iostream> using namespace std; int m; int answer; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> m; string input, int x; for (int i = 0; i < m; i++) { cin >> input; if (input == "add"){ cin >> x; answer |= (1 << x); } else if (input == "remove"){ cin >> x; answer &= ~(1 << x); } else if (input == "check") { cin >> x; if (answer & (1 << x)){ cout << "1" << "\n"; } else { cout << "0" << "\n"; } } else if (input == "toggle") { cin >> x; answer ^= (1 << x); } else if (input == "all") { answer |= ((1 << 21) - 1); } else if (input == "empty") { //answer &= ~((1 << 21) - 1); answer = 0; } } return 0; }
'⭐ 코딩테스트 > 백준' 카테고리의 다른 글
[백준 14391번 C/C++] 종이 조각 (0) | 2024.08.07 |
---|---|
[백준 15661번 C++] 링크와 스타트 (0) | 2024.08.06 |
[백준 1052번 C/C++] 물병 (0) | 2024.08.05 |
[백준 16938번 C/C++] 캠프 준비 (0) | 2024.08.02 |
[백준 2961번 C/C++] 도영이가 만든 맛있는 음식 (0) | 2024.08.01 |
댓글
이 글 공유하기
다른 글
-
[백준 14391번 C/C++] 종이 조각
[백준 14391번 C/C++] 종이 조각
2024.08.07 -
[백준 15661번 C++] 링크와 스타트
[백준 15661번 C++] 링크와 스타트
2024.08.06 -
[백준 1052번 C/C++] 물병
[백준 1052번 C/C++] 물병
2024.08.05 -
[백준 16938번 C/C++] 캠프 준비
[백준 16938번 C/C++] 캠프 준비
2024.08.02
댓글을 사용할 수 없습니다.