P5266 【深基17.例6】学籍管理

\(map\)模板题

unordered_map<string,int> mp;
int n;

int main()
{
    cin>>n;

    for(int i=0;i<n;i++)
    {
        int op;
        string name;
        int score;
        cin>>op;

        if(op == 1)
        {
            cin>>name>>score;
            mp[name]=score;
            puts("OK");
        }
        else if(op == 2)
        {
            cin>>name;
            if(mp.count(name)) cout<<mp[name]<<endl;
            else puts("Not found");
        }
        else if(op == 3)
        {
            cin>>name;
            if(mp.count(name))
            {
                mp.erase(name);
                puts("Deleted successfully");
            }
            else puts("Not found");
        }
        else cout<<mp.size()<<endl;

    }

    //system("pause");
}
posted @ 2020-09-03 19:09  Dazzling!  阅读(227)  评论(0编辑  收藏  举报