CPPSET - Tập hợp động
Tác giả: flashmt
Ngôn ngữ: C++
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<set>
#define fr(a,b,c) for (a=b;a<=c;a++)
using namespace std;
set<int> a;
set<int>::iterator it;
int main()
{
int x,z;
while (1)
{
scanf("%d",&z);
if (!z) break;
if (z<3 || z>4) scanf("%d",&x);
if (z==1) a.insert(x);
if (z==2) a.erase(x);
if (z==3)
{
if (a.empty()) printf("empty\n");
else printf("%d\n",*a.begin());
}
if (z==4)
{
if (a.empty()) printf("empty\n");
else printf("%d\n",*(--a.end()));
}
if (z==5)
{
if (a.empty()) printf("empty\n");
else
{
it=a.upper_bound(x);
if (it==a.end()) printf("no\n");
else printf("%d\n",*it);
}
}
if (z==6)
{
if (a.empty()) printf("empty\n");
else
{
it=a.lower_bound(x);
if (it==a.end()) printf("no\n");
else printf("%d\n",*it);
}
}
if (z==7)
{
if (a.empty()) printf("empty\n");
else
{
it=a.lower_bound(x);
if (it==a.begin()) printf("no\n");
else printf("%d\n",*(--it));
}
}
if (z==8)
{
if (a.empty()) printf("empty\n");
else
{
it=a.upper_bound(x);
if (it==a.begin()) printf("no\n");
else printf("%d\n",*(--it));
}
}
}
return 0;
}