map板子,求调
查看原帖
map板子,求调
1234924
lsd110504lsd楼主2024/12/11 18:52
#include<iostream>
#include<map>
using namespace std;
map<int,int> mp; 
int main()
{
	int t;
	cin>>t;
	for(int i=1;i<=t;i++)
	{
		short b;
		int len;
		cin>>b>>len;
		if(b==1)
		{
			if(mp.count(len))
			{
				cout<<"Already Exist"<<endl;
			}
			else{
				mp[len]=1;
			}
		}
		else{
			if(mp.empty())
				cout<<"Empty"<<endl;
			if(mp.count(len))
			{
				cout<<len<<endl;
				mp.erase(len);
			}
			else
			{
				int l=len,j=len;
				while(l>=1||j<=99999999)
				{
					l--;
					j++;
					if(mp.count(l))
					{
						cout<<l<<endl;
						mp.erase(l);
						goto qw;
					}
					if(mp.count(j))
					{
						cout<<j<<endl;
						mp.erase(j);
						goto qw;
					}
				}
				qw:
					;
			}
		}
	}
	return 0;
}
2024/12/11 18:52
加载中...