为什么我样例过了测试点全WA啊(恼)
查看原帖
为什么我样例过了测试点全WA啊(恼)
551204
Nahida1118楼主2024/12/21 17:49

语言:C++17

开不开O2随便

代码:

#include <iostream>
#include <map>
#include <cstdlib>
#include <string>
#include <utility>
#include <stdexcept>
#include <cstdint>

typedef std::int32_t Int;

int main()
{
    using namespace std;
    Int n;
    cin >> n;
    map<string, Int> mp;
    while(n--)
    {
        Int op;
        cin >> op;
        pair<string, Int> stu;
        switch(op)
        {
        case 1:
            cin >> stu.first >> stu.second;
            mp.insert(stu);
            cout << "OK" << endl;
            break;
        case 2:
            cin >> stu.first;
            try
            {
                cout << mp.at(stu.first) << endl;
            }
            catch(const out_of_range& e)
            {
                cout << "Not found" << endl;
            }
            break;
        case 3:
            cin >> stu.first;
            if(mp.erase(stu.first))
            {
                cout << "Deleted successfully" << endl;
            }
            else
            {
                cout << "Not found" << endl;
            }
            break;
        case 4:
            cout << mp.size() << endl;
            break;
        }
    }
    return EXIT_SUCCESS;
}
2024/12/21 17:49
加载中...