木材仓库 set 加set<int>::iterator

 

 

#include <iostream>
#include <set>

using namespace std;

int n, op, t;
set<int>::iterator lwb, l2, l3;
set<int> s;
int main(){
    freopen("1.txt","r",stdin);
	cin >> n;
	for (int i = 1;i <= n;i ++){
		cin >> op >> t;
		if (op == 1){
			   if(s.find(t)== s.end())s.insert(t);
            else cout<<"Already Exist"<<endl;
		}
		else {
			if (s.empty()){
				cout << "Empty\n";
				continue;
			}
			if (s.find(t) != s.end()) cout << t, s.erase(s.find(t));
			else {
				lwb = l2 = l3 = s.lower_bound(t);
				if (lwb == s.begin()) cout << *lwb, s.erase(lwb);
				else if (lwb == s.end()) cout << *(-- l3), s.erase(l3);
				else if (*lwb - t < t - *(-- l2)) cout << *(l3), s.erase(l3);
				else cout << *(-- l3), s.erase(l3);
			}
			cout << endl;
		}
	}
}

找某值 find(x)==end(),表示找不到

否则表示找到了

这里找不到第一个大于等于 的数(长度)分四种 最 接近的 优先  后 要求短的优先

1 在最前面 最理想 直接输出后删除()

2 在最后面 输出前一个

3 在中间 比较两种差 if() 输出后面,

       else  输出前面的,因为前面的优先,会多一点情况

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值