标签:else www class alt amp size tar 返回 ready
一.集合概览
二.操作
set自带的函数常用的有10种:
代码:
1 #include<iostream>
2 #include<set>
3 using namespace std;
4 int main()
5 {
6 set<int> s;
7 int n;
8 cin >> n;
9 for (int i = 0; i < n; i++)
10 {
11 int tmp1, tmp2;
12 cin >> tmp1 >> tmp2;
13 if (tmp1 == 1)
14 {
15 if (s.find(tmp2) != s.end())
16 cout << "Already Exist" << endl;
17 else
18 s.insert(tmp2);
19 }
20 if (tmp1 == 2)
21 {
22 if (s.empty())
23 cout << "Empty" << endl;
24 else
25 {
26 auto it1 = s.lower_bound(tmp2);
27 auto it2 = it1;
28 if (it2 != s.begin())
29 it2--;
30 if (it1!=s.end()&&(tmp2 - *it2) > (*it1 - tmp2))
31 it2 = it1;
32 cout << *it2 << endl;
33 s.erase(it2);
34 }
35 }
36 }
37 return 0;
38 }
标签:else www class alt amp size tar 返回 ready
原文地址:https://www.cnblogs.com/luoyoooo/p/12560594.html