Pagini recente » Cod sursa (job #1272562) | Cod sursa (job #1325997) | Cod sursa (job #2235152) | Cod sursa (job #1568958) | Cod sursa (job #2751525)
#include <iostream>
#include <fstream>
#include <set>
using namespace std;
ifstream fin("zeap.in");
ofstream fout("zeap.out");
set<int> Z;
void inserare(int x)
{
Z.insert(x);
}
int sterge(int x)
{
if(Z.count(x))
{
Z.erase(x);
return 1;
}
else return -1;
}
int main()
{
string comanda;
int x;
while(fin>>comanda)
{
if(comanda == "I")
{
fin>>x;
inserare(x);
}
else if(comanda == "S")
{
fin>>x;
int val = sterge(x);
if(val == -1) fout<<-1<<"\n";
}
else if(comanda == "C")
{
fin>>x;
fout<<Z.count(x)<<"\n";
}
else if(comanda == "MAX")
{
if(Z.size() >= 2)
{
auto maxim = Z.rbegin();
auto minim = Z.begin();
x = *maxim - *minim;
fout<<x<<"\n";
}
else fout<<-1<<"\n";
}
else if(comanda == "MIN")
{
if(Z.size() >= 2)
{
auto it = Z.begin();
int x = *it;
it++;
int y = *it;
fout<< y - x <<"\n";
}
else fout<<-1<<"\n";
}
}
}