중복 자동 제거
오름차순 정렬
#include <iostream>
#include <set>
using namespace std;
int main() {
set<int> s; // 빈 set 선언
set<int> s2 = {3, 1, 4, 1, 5, 9}; // 중복 자동 제거됨: {1, 3, 4, 5, 9}
}
set<int> s;
s.insert(5);
s.insert(1);
s.insert(3);
s.insert(5); // 중복 추가 → 무시됨
s.erase(3); // 값 3 삭제
auto it = s.find(5);
s.erase(it); // 값 5 삭제
if (s.count(3)) cout << "3 있음";
else cout << "3 없음";
bool형식
auto it = s.find(3);
if (it != s.end()) cout << "3 있음: " << *it;
반환값: 존재하면 해당 원소의 이터레이터, 없으면 s.end()
for (auto it = s.begin(); it != s.end(); it++) {
cout << *it << " ";
}
set<int> s = {1, 3, 5, 7, 9};
cout << *s.lower_bound(4); // 5
cout << *s.upper_bound(5); // 7
cout << s.size(); // 원소 개수 출력
cout << s.empty(); // 비어있으면 1, 아니면 0 반환
s.clear(); // set 비우기