CPPSET - Tập hợp động
Tác giả: hieult
Ngôn ngữ: C++
#include <cstdio>
#include <set>
#include <iostream>
//#include <conio.h>
using namespace std;
int main()
{
//freopen("CPPSET.in","r",stdin);
set<int, less<int> > s,s1;
set<int>::iterator it,it1;
int thaotac,x;
while(scanf("%d",&thaotac)>0 && thaotac>0)
{
if(thaotac == 1)
{
scanf("%d",&x);
s.insert(x);
s1.insert(-x);
}
else if(thaotac == 2)
{
scanf("%d",&x);
it = s.find(x);
it1 = s1.find(-x);
if(it!=s.end())
{
s.erase(it);
s1.erase(it1);
}
}
else if(thaotac == 3)
{
if(s.empty())
{
printf("empty\n");
}
else
{
it = s.begin();
printf("%d\n",*it);
}
}
else if(thaotac == 4)
{
if(s.empty())
printf("empty\n");
else
{
it = s.end();it--;
printf("%d\n",*it);
}
}
else if(thaotac==5)
{
scanf("%d",&x);
x;
if(s.empty())
printf("empty\n");
else
{
it = s.upper_bound(x);
if(it==s.end())
printf("no\n");
else
printf("%d\n",*it);
}
}
else if(thaotac==6)
{
scanf("%d",&x);
if(s.empty())
printf("empty\n");
else
{
it = s.lower_bound(x);
if(it==s.end())
printf("no\n");
else
printf("%d\n",*it);
}
}
else if(thaotac==7)
{
scanf("%d",&x);
x = -x;
if(s1.empty())
printf("empty\n");
else
{
it = s1.upper_bound(x);
if(it==s1.end())
printf("no\n");
else
printf("%d\n",-(*it));
}
}
else if(thaotac==8)
{
scanf("%d",&x);
x = -x;
if(s1.empty())
printf("empty\n");
else
{
it = s1.lower_bound(x);
if(it==s1.end())
printf("no\n");
else
printf("%d\n",-(*it));
}
}
}
//getch();
}