Problem
https://www.acmicpc.net/problem/11723
11723번: 집합
첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다.
www.acmicpc.net

Solution
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
int n; // 연산의 수
int x; // 주어지는 수
int arr[21]; // 공집합 S
string str=""; // 명령어
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n;
for(int i=0;i<n;i++){
cin >> str;
if(str=="add"){
cin >> x;
if(arr[x]==0)
arr[x]=1;
}
if(str=="remove"){
cin >> x;
if(arr[x]==1)
arr[x]=0;
}
if(str=="check"){
cin >> x;
if(arr[x]==1)
cout << "1\n";
else
cout << "0\n";
}
if(str=="toggle"){
cin >> x;
if(arr[x]==1)
arr[x]=0;
else
arr[x]=1;
}
if(str=="all"){
for(int i=1;i<21;i++){
arr[i]=1;
}
}
if(str=="empty"){
// memset(arr, 0, sizeof(arr));
for(int i=1;i<21;i++){
arr[i]=0;
}
}
}
return 0;
}
Reference
https://nanyoungkim.tistory.com/47
[C++] 백준 11723번 - 집합 (배열/비트마스크)
문제 링크 : www.acmicpc.net/problem/11723 11723번: 집합 첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다. www.a
nanyoungkim.tistory.com
https://mygumi.tistory.com/361
비트마스크(BitMask) 는 무엇인가? :: 마이구미
이 글은 비트마스크(BitMask) 기법에 대해 다룬다. 특정 알고리즘이 아닌, bit 를 활용한 테크닉이라고 할 수 있다. bit 는 low level 이 아닌 경우에는 크게 비트를 다룰 일은 없어보이지만, 분명 이해
mygumi.tistory.com
'코딩 테스트 > 백준 (C++, Python)' 카테고리의 다른 글
cpp) 백준 2606: 바이러스 (0) | 2023.07.05 |
---|---|
cpp) 백준 1012: 유기농 배추 (0) | 2023.07.04 |
cpp) 백준 1874: 스택 수열 (2) | 2023.06.29 |
cpp) 백준 2805: 나무 자르기 (0) | 2023.06.27 |
cpp) 백준 13305: 주유소 (0) | 2023.06.27 |