Pagini recente » Cod sursa (job #2424289) | Cod sursa (job #2422885) | Cod sursa (job #2754101) | Cod sursa (job #3153165) | Cod sursa (job #2751673)
#include <bits/stdc++.h>
using namespace std;
ifstream in ("zeap.in");
ofstream out ("zeap.out");
set <int> Set;
string comanda;
set<int>::iterator first, last;
int main()
{
while(in>>comanda)
{
if(comanda=="I")
{ int x;
in>>x;
Set.insert(x);
}
if(comanda=="S")
{ int x;
in>>x;
if(Set.find(x)!=Set.end())
Set.erase(x);
else out<<-1<<'\n';
}
if(comanda=="C")
{ int x;
in>>x;
if(Set.find(x)!=Set.end())
out<<1<<'\n';
else out<<0<<'\n';
}
if(comanda=="MIN")
{
if(Set.size()<2)
out<<-1<<'\n';
else
{ int difmin=2e9;
for(first=Set.begin();first!=Set.end();first++)
{
last=first;
last++;
if(last!=Set.end())
difmin=min(difmin,(*last-*first));
}
out<<difmin<<'\n';
}
}
if(comanda=="MAX")
{
if(Set.size()<2)
out<<-1<<'\n';
else
{
int poz1,poz2;
first=Set.begin();
last=Set.end();
last--;
out<<(*last-*first)<<'\n';
}
}
}
return 0;
}