题目链接: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;
}