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;
}