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

    科技2024-04-12  94

    题目链接:https://www.luogu.com.cn/problem/P5266


    查找与删除,选用STL容器中的unordered_map

    #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <unordered_map> using namespace std; int n; unordered_map<string, int> h; int main(){ cin >> n; while (n -- ){ int a; cin >> a; if (a == 1) { string b; int c; cin >> b >> c; h[b] = c; puts("OK"); } else if (a == 2){ string b; cin >> b; if (h.count(b)) cout << h[b] << endl; else puts("Not found"); } else if (a == 3){ string b; cin >> b; if (h.count(b)) h.erase(b), puts("Deleted successfully"); else puts("Not found"); } else { cout << h.size() << endl; } } return 0; }
    Processed: 0.016, SQL: 9