NC17889 新建 Microsoft Office Word 文档

STL+模拟.
1.开一个bool vis[i]表示第i个文档是否存在,然后建一个set存放没有建立的文件.
2.建立文档:直接取set的首元素,vis[i] = true.
3.删除文档:查询vis,若存在,输出"成功";否则,输出"失败".

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
const int maxn = 1e5+5;
bool vis[maxn] = {false};
set<int> s;

inline ll read()
{
    ll s = 0, w = 1; 
    char ch = getchar();
    while (ch < 48 || ch > 57) 
    	{ 
    		if (ch == '-') 
    			w = -1; 
    		ch = getchar(); 
    	}
    while (ch >= 48 && ch <= 57) 
    	s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return s * w;
}

int main(int argc, char const *argv[])
{
	int op;
	op = read();
	for (int i = 1; i < maxn; ++i)
	{
		s.insert(i);
	}
	while(op--)
	{
		string str;
		int id;
		cin >> str;
		if (str == "New")
		{
			auto it = s.begin();
			vis[*it] = true;
			cout << *it << endl;
			s.erase(it);
		}
		else
		{
			id = read();
			if (vis[id] == true)
			{
				cout << "Successful" << endl;
				vis[id] = false;
				s.insert(id);
			}
			else
			{
				cout << "Failed" << endl;
			}

		}

	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值