我用Map,本地已过
#include <iostream>
#include <map>
using namespace std;
map<int,int> mp;
int type,n;
int Len;
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>type;
if(type==1)
{
cin>>Len;
if(mp.count(Len))cout<<"Already Exis\n";
else mp[Len]=Len;
}
else if(type==2)
{
cin>>Len;
if(mp.empty())cout<<"Empty\n";
else if(mp.count(Len)){
cout<<Len<<endl;
mp.erase(Len);
}else if(!mp.count(Len)&&!mp.empty()){
int x=Len,y=Len;
while(1){
x--,y++;
if(mp.count(x)||mp.count(y))
{
if(mp.count(x))
{
cout<<x<<endl;
mp.erase(x);
}else if(mp.count(y))
{
cout<<y<<endl;
mp.erase(y);
}else cout<<x<<endl,mp.erase(x);
break;
}
}
}
}
}
return 0;
}