P5266 【深基17.例6】学籍管理 【map】
题目
https://www.luogu.com.cn/problem/P5266
思路
使用map记录数据,注意map以下函数的使用
代码
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<map> using namespace std; map<string, int>e; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int a, b; string c; cin >> a; if (a != 4)cin >> c; if (a == 1) { cin >> b; e[c] = b; cout << "OK" << endl; } else if (a == 2) { if (!e.count(c))cout << "Not found" << endl; else cout << e[c] << endl; } else if (a == 3) { if(e.count(c)){ e.erase(c); cout << "Deleted successfully" << endl; } else cout << "Not found" << endl; } else cout << e.size()<<endl; } }