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
32
33
34
35
36
37
38
39
40
|
#define _CRT_SECURE_NO_WARNINGS
#define INF 187654321
#include<iostream>
#include <set>
using namespace std;
int main() {
set<int> s; // 중복을 허용하려면 multiset
s.insert(7); // 삽입
s.insert(2);
s.insert(9);
set<int>::iterator it;
for (it = s.begin(); it != s.end(); it++) { // 조회, 자동으로 정렬되기 때문에 2, 7, 9 출력
cout << *it << " ";
}
cout << endl;
it = s.find(8); // 검색 및 삭제
if (it != s.end()) cout << "존재" << endl; // 검색 성공여부 확인
else cout << "미존재" << endl;
it = s.find(2);
s.erase(it);
for (it = s.begin(); it != s.end(); it++) { // 조회
cout << *it << " ";
}
return 0;
}
|
cs |
반응형
'자료구조 + 알고리즘' 카테고리의 다른 글
구간합(Prefix sum), 투 포인터 (0) | 2021.09.13 |
---|---|
이분탐색 (Binary Search) (0) | 2021.09.13 |
(C++) map container (0) | 2021.09.11 |
(C++) 문자열 다루기 (0) | 2021.09.11 |
Brute-force Search (0) | 2021.09.05 |