Pagini recente » Cod sursa (job #2388712) | Cod sursa (job #402713) | Cod sursa (job #2769176) | Cod sursa (job #1551861) | Cod sursa (job #652010)
Cod sursa(job #652010)
#include <stdio.h>
#include <string.h>
#include <set>
#define LMAX 51
using namespace std;
char line[LMAX];
int poz,nr;
inline int cif(char x)
{
return x>='0' && x<='9';
}
void read()
{
while (!cif(line[poz+1])) poz++;
while (cif(line[poz+1])){poz++; nr=nr*10+line[poz]-'0';}
}
set <int> A;
set <int> :: iterator it1,it2,it3;
multiset <int> B;
multiset <int> :: iterator it;
int main()
{
freopen("zeap.in","r",stdin);
freopen("zeap.out","w",stdout);
while (!feof(stdin))
{
fgets(line+1,LMAX,stdin);
poz=0; nr=0;
if (line[1]=='I')
{
read();
if (A.find(nr)==A.end())
{
A.insert(nr);
it1=A.find(nr); it2=it1; it2++;
if (it2!=A.end())
B.insert((*it2)-(*it1));
if (it1!=A.begin())
{
it2=it1; it2--;
B.insert((*it1)-(*it2));
}
}
}
if (line[1]=='S')
{
read();
it1=A.find(nr);
if (A.find(nr)==A.end())
printf("-1\n");
else
{
it2=it1; it2++; it3=it1;
if (it2!=A.end())
{
B.erase((*it2)-(*it1));
}
if (it1!=A.begin())
{
it3--;
B.erase((*it1)-(*it3));
}
if (it2!=A.end() && it1!=A.begin())
B.insert((*it2)-(*it3));
A.erase(it1);
}
}
if (line[1]=='C')
{
read();
it1=A.find(nr);
if (it1!=A.end())
printf("1\n");
else
printf("0\n");
}
if (line[1]=='M' && line[2]=='A')
{
if (A.size()<2)
printf("-1\n");
else
{
it1=A.end(); it1--;
printf("%d\n",(*it1)-(*A.begin()));
}
}
if (line[1]=='M' && line[2]=='I')
{
if (A.size()<2)
printf("-1\n");
else
printf("%d\n",(*B.begin()));
}
memset(line,0,sizeof(line));
}
return 0;
}