Cod sursa(job #2751673)

Utilizator Marie02THGStanescu Maria Raluca Marie02THG Data 15 mai 2021 15:47:41
Problema Zeap Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.35 kb
#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;
}