一、解题思路
采用unordered_map建立起QQ号和pwd的映射,仅此而已
二、解题代码
#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;
int main(){
int N;
cin >> N;
unordered_map<string, string> ump;
for(int i = 0; i < N; i++){
char cmd;
string id, pwd;
cin >> cmd >> id >> pwd;
if(cmd == 'L'){
if(ump.find(id) == ump.end()) cout << "ERROR: Not Exist" << endl;
else if(ump[id] == pwd) cout << "Login: OK" << endl;
else cout << "ERROR: Wrong PW" << endl;
}
else if(cmd == 'N'){
if(ump.find(id) != ump.end()) cout << "ERROR: Exist" << endl;
else {
ump[id] = pwd;
cout << "New: OK" << endl;
}
}
}
return 0;
}

京公网安备 11010502036488号