Cod sursa(job #1400240)

Utilizator ThomasFMI Suditu Thomas Thomas Data 25 martie 2015 10:31:29
Problema Zeap Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <fstream>
#include <set>
using namespace std;

ifstream f("zeap.in");
ofstream g("zeap.out");

set<int> S;
set<int>::iterator it,it2;

int main()
{
    char c[5];
    int x;

    while(f>>c)
    {
        if(c[0] == 'I')
        {
            f>>x;
            S.insert(x);
        }
        else if(c[0] == 'S')
        {
            f>>x;
            it = S.find(x);
            if(it == S.end()) g<<"-1\n";
            else S.erase(it);
        }
        else if(c[0] == 'C')
        {
            f>>x;
            it = S.find(x);
            if(it == S.end()) g<<"0\n";
            else g<<"1\n";
        }
        else if(c[1] == 'A')
        {
            it = S.end(); --it;
            g<<(*it) - (*S.begin())<<"\n";
        }
        else if(c[1] == 'I')
        {
            x = 2100000000;
            for(it=S.begin();;)
            {
                it2 = it;
                ++it;
                if(it == S.end()) break;
                x = min(x,(*it)-(*it2));
            }
            g<<x<<"\n";
        }
    }

    f.close();
    g.close();
    return 0;
}