求助代码!
查看原帖
求助代码!
1054257
AndyCGM楼主2024/1/16 14:11
#include <bits/stdc++.h>
using namespace std;
map <string,int> ds;
int main(){
    int n,opt,num,ans;
    string name;
    cin >> n;
    while (n--){
        cin >> opt;
        if (opt == 1){
            cin >> name >> num;
            ds[name]=num;
            cout << "OK" << endl;
        }else if (opt == 2){
            cin >> name;
            if (ds.find(name)!=ds.end())    cout << ds[name] << endl;
            else    cout << "Not found";
        }else if (opt == 3){
            if (ds.find(name)!=ds.end()){
                ds.erase(ds.find(name));
                cout << "Deleted successfully" << endl;
            }else   cout << "Not found" << endl;
        }else   cout << ds.size() << endl;
        
    }
}
2024/1/16 14:11
加载中...