rt,明明删了,输出时元素个数还是1........
#include <iostream>
#include <map>
using namespace std;
map <string,int> a;
int main()
{
int Q;cin>>Q;
//初始化
while(Q--)
{
int x;cin>>x;
if(x==1)
{
string name; int score;cin>>name>>score;
a[name]=score;
cout<<"OK"<<endl;
continue;
}
//插入与修改
if(x==2)
{
string name;cin>>name;
if(a[name]) cout<<a[name]<<endl;
else cout<<"Not found"<<endl;
continue;
}
//查询
if(x==3)
{
string name;cin>>name;
if(a[name])
{
a.erase(name);
cout<<"Deleted successfully"<<endl;
// cout<<a.size()<<endl;
//这是输出的是0,但到操作4时又变成1了QwQ
}
else cout<<"Not found"<<endl;
continue;
}
//删除
if(x==4)
{
cout<<a.size()<<endl;
}
//汇总
}
//处理
return 0;
}
/*
in:
5
1 lxl 10
2 lxl
3 lxl
2 lxl
4
out:
OK
10
Deleted successfully
Not found
0
*/
这段代码样例的输出:
OK
10
Deleted successfully
Not found
1