写法比较简单,码量不大,题目不难,纯模拟。最多map,本人代码如下。
#include<bits/stdc++.h>
using namespace std;
map<string,long long>h;
map<string,bool>m;
int main(){
long long a,b,c,d,e=0;
string bb;
cin>>a;
for(int i=1;i<=a;i++){
cin>>b;
if(b==1){
cin>>bb;
cin>>c;
h[bb]=c;
cout<<"OK"<<endl;
if(m[bb]==0){
e++;
}
m[bb]=1;
continue;
}
if(b==2){
cin>>bb;
if(m[bb]==1){
cout<<h[bb]<<endl; continue;
}else{
cout<<"Not found"<<endl; continue;
}
}
if(b==3){
cin>>bb;
if(m[bb]==1){
cout<<"Deleted successfully"<<endl;
e--;
m[bb]=0;
continue;
}else{
cout<<"Not found"<<endl;continue;
}
}
if(b==4){
cout<<e<<endl;
continue;
}
}
return 0;
}