STL天下第一!C++天下第一!
用map不要太爽了~
#include <iostream>
#include <map>
using namespace std;
map<string ,int > t;//存储姓名和分数
typedef map<string ,int >::iterator It;
int main()
{
int n,x;
cin>>n;
string str;
int score;
for(int i=1;i<=n;i++)
{
cin>>x;
if(x==1)
{
cin>>str;
cin>>score;
t.find(str)==t.end() ? t[str]=score :t.find(str)->second=score;
cout<<"OK"<<endl;
}
else if(x==2)
{
cin>>str;
cout<<(t.find(str)==t.end() ? "Not found":to_string(t.find(str)->second))<<endl;
}
else if(x==3)
{
cin>>str;
if(t.find(str)==t.end())
{
cout<<"Not found"<<endl;
}
else
{
t.erase(str);
cout<<"Deleted successfully"<<endl;
}
}
else
{
cout<<t.size()<<endl;
}
}
return 0;
}