Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- BOJ
- C#
- 이펙티브코틀린
- 운영체제
- 토마토
- 스프링 핵심 원리
- Window-Via-c/c++
- redis
- 에러핸들링
- 우아한레디스
- 윤성우 저자
- n타일링2
- 우아한 테크 세미나
- OS
- 제프리리처
- 2475번
- HTTP
- Operating System
- Spring
- 스프링 입문
- 10026번
- C++
- 열혈 TCP/IP 소켓 프로그래밍
- FIFO paging
- TCP/IP
- 열혈 tcp/ip 프로그래밍
- Operating System.
- 김영한
- Four Squares
- inflearn
Archives
- Today
- Total
나의 브을로오그으
[c++] 11723번 : 집합 본문
https://www.acmicpc.net/problem/11723
11723번: 집합
첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다.
www.acmicpc.net
#include <iostream>
#include <cstring>
using namespace std;
#define DEFAULT_LENGTH 20
class Set
{
public:
Set()
: arr{ false, },
length(0),
capacity(DEFAULT_LENGTH)
{
}
~Set()
{
}
int add(int data)
{
int ins = -1;
if (arr[data] == false)
{
arr[data] = true;
ins = data;
++length;
}
return ins;
}
int remove(int data)
{
int rem = -1;
if (arr[data] == true)
{
arr[data] = false;
rem = data;
--length;
}
return rem;
}
bool check(int data)
{
return arr[data];
}
void toggle(int data)
{
if (arr[data] == true)
{
arr[data] = false;
--length;
}
else
{
arr[data] = true;
++length;
}
}
void all()
{
memset(arr, 1, sizeof(arr));
length = capacity;
}
void empty()
{
memset(arr, 0, sizeof(arr));
length = 0;
}
private:
bool arr[DEFAULT_LENGTH + 1];
int length;
int capacity;
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
string input;
Set S;
int M, x;
cin >> M;
cin.ignore(256, '\n');
for (int i = 0; i < M; ++i)
{
cin >> input;
if (input == "add")
{
cin >> x;
S.add(x);
}
else if (input == "remove")
{
cin >> x;
S.remove(x);
}
else if (input == "check")
{
cin >> x;
cout << S.check(x) << '\n';
}
else if (input == "toggle")
{
cin >> x;
S.toggle(x);
}
else if (input == "all")
{
S.all();
}
else if (input == "empty")
{
S.empty();
}
else
{
/* Wrong Type Instruction */
}
}
return 0;
}
'알고리즘 > BaekJoon' 카테고리의 다른 글
[c++] 11726번 : 2Xn 타일링 (0) | 2022.09.20 |
---|---|
[c++] 11724번 : 연결 요소의 개수 (0) | 2022.09.20 |
[c++] 11659번 : 구간 합 구하기 4 (0) | 2022.09.19 |
[c++] 11403번 : 경로 찾기 (0) | 2022.09.19 |
[c++] 11399번 : ATM (0) | 2022.09.19 |