c++

4396y 发表于 1年前 · 关联问题 C++ 语法练习之 map

include "pch.h"

include

include

int main() {

int n; map<string, int> mymap; priority_queue<Element > pq; cin >> n; n = n + 1; while (n--) { if (n < 1 || n>3*10*10*10*10*10*10) { return 0; } int m; cin >>m; switch (m) { case 1: { char menmery[30]; cin >> menmery; int num; cin >> num; string str1 = menmery; // str1.pop_back(); if (mymap.find(str1) == mymap.end()) { //没找到 mymap.insert(pair<string,int> (str1,num)); } break; } case 2: { char menmery[30]; cin >> menmery; string str1 = menmery; //str1.pop_back(); if (mymap.find(str1) == mymap.end()) { cout << "no\n";

} else { mymap.erase(str1); } break; } case 3: { char menmery[30]; cin >> menmery; string str1 = menmery; if (mymap.find(str1) == mymap.end()) {

//没找到 cout << "no\n"; } else { cout << mymap[str1]<<"\n"; } break; } } }

}