袁老师版题解
2024-06-02 11:52:58
发布于:广东
15阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
string d,f;//d=操作,f=指纹;
vector <string> v; //向量容器,类型为string,名为v
while(n--)
{
cin >> d;
if(d=="ADD")
{
cin >> f;
//查找find(容器开始内存,结束内存地址,要找的东西)
if(1==1)
{
v.push_back(f);//向最后推一个f变量
cout << "success\n";
}
else
{
cout << "already exists\n";
}
}
if(d=="DEL")
{
cin >> f;
if( find(v.begin(), v.end(), f) == v.end())
{
cout << "non-existent\n";
}
else{
//删除 找到的送代器对象
v.erase( find(v.begin(), v.end(), f) );
cout << "success\n";
}
}
if(d=="VIEW")
{
if(v.size()==0)
cout << "empty\n";
else{
for(int i=0; i<v.size(); i++)
cout << i+1 << ". " << v[i] << endl;
}
}
if(d=="UNLOCK")
{
cin >> f;
if( find(v.begin(), v.end(), f) == v.end() )
cout << "NO\n";
else
cout << " Yes\n";
}
}
return 0;
}
这里空空如也
有帮助,赞一个