https://www.acmicpc.net/problem/11723
* 이 문제는 비트마스킹으로 푸는 문제라던데, 이후에 공부해보자.
참고자료 : https://hagisilecoding.tistory.com/54
C++ 비트 마스킹 (비트 연산) [컴공과고씨]
데이터 타입에는 각 메모리 사용 크기가 있다. 만약 int 라고 하면 4byte 즉, 32 bit의 크기를 가진다. 표현하면 0000 0000 0000 0000 0000 0000 0000 0000이 될 것이다. (0과 1을 씀) 만약 아이템이 있고 없고를 구
hagisilecoding.tistory.com
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
int number[21];
int main(void) {
// C++ Init
ios::sync_with_stdio(false);
cin.tie(NULL);
int input1;
int num;
string str;
cin >> input1;
for (int i = 0; i < input1; i++) {
cin >> str;
if (str == "add") {
cin >> num;
if(number[num] == 0) number[num]++;
}
if (str == "remove") {
cin >> num;
if (number[num] != 0) number[num]--;
}
if (str == "check") {
cin >> num;
if (number[num] == 1) cout << "1" << endl;
else cout << "0" << endl;
}
if (str == "toggle") {
cin >> num;
if (number[num] == 0) number[num]++;
else number[num]--;
}
if (str == "all") {
for (int i = 0; i < 21; i++) {
number[i] = 1;
}
}
if (str == "empty") {
for (int i = 0; i < 21; i++) {
number[i] = 0;
}
}
}
}
'Algorithm > 백준' 카테고리의 다른 글
C++ 알고리즘 - 백준 1764 듣보잡 (unordered_map) (0) | 2025.01.04 |
---|---|
C++ 알고리즘 - 백준 1620 나는야 포켓몬 마스터 이다솜 (unordered_map) (0) | 2025.01.04 |
C++ 알고리즘 - 백준 1654 랜선 자르기 (이분/매개변수 탐색) (0) | 2025.01.04 |
C++ 알고리즘 - 백준 2108 통계학 (0) | 2025.01.04 |
C++ 알고리즘 - 백준 1966 프린터 큐 (0) | 2025.01.01 |