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

#include <bits/stdc++.h>

using namespace std;
int n;
string name;
int opt, score;

unordered_map<string, int> _map;

int main() {
    cin >> n;
    while (n--) {
        cin >> opt;
        switch (opt) {
            case 1:
                cin >> name >> score;
                _map[name] = score;
                cout << "OK" << endl;
                break;
            case 2:
                cin >> name;
                if (_map.count(name) > 0) cout << _map[name] << endl;
                else cout << "Not found" << endl;
                break;
            case 3:
                cin >> name;
                if (_map.count(name) > 0) _map.erase(name), cout << "Deleted successfully" << endl;
                else cout << "Not found" << endl;
                break;
            case 4:
                cout << _map.size() << endl;
                break;
        }
    }
    return 0;
}
posted @ 2021-08-07 10:04  糖豆爸爸  阅读(64)  评论(0编辑  收藏  举报
Live2D