文章目录
1. 题目来源
2. 题目解析
水题,unordered_map<>
基本使用。
代码:
// https://www.luogu.com.cn/problem/P5266
#include <iostream>
#include <cstdio>
#include <string>
#include <unordered_map>
using namespace std;
int n;
unordered_map<string, int> h;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i ++ ) {
int op;
string s;
int sum;
scanf("%d", &op);
if (op == 1) {
cin >> s >> sum;
h[s] = sum, printf("OK\n");
}
else if (op == 2) {
cin >> s;
if (h.count(s)) printf("%d\n", h[s]);
else printf("Not found\n");
}
else if (op == 3) {
cin >> s;
if (h.count(s)) h.erase(s), printf("Deleted successfully\n");
else printf("Not found\n");
}
else printf("%d\n", h.size());
}
}