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 |
Tags
- Spring
- 이펙티브코틀린
- 운영체제
- Operating System.
- 우아한 테크 세미나
- 열혈 TCP/IP 소켓 프로그래밍
- Operating System
- Window-Via-c/c++
- 토마토
- OS
- redis
- FIFO paging
- 우아한레디스
- Four Squares
- C#
- C++
- 스프링 핵심 원리
- 윤성우 저자
- 제프리리처
- n타일링2
- BOJ
- 스프링 입문
- 10026번
- 열혈 tcp/ip 프로그래밍
- 김영한
- 에러핸들링
- 2475번
- HTTP
- inflearn
- TCP/IP
Archives
- Today
- Total
나의 브을로오그으
[c++] 11723번 : 집합 본문
https://www.acmicpc.net/problem/11723
#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 |