7-10 QQ帳戶的申請與登陸 (25 分)
阿新 • • 發佈:2018-12-10
實現QQ新帳戶申請和老帳戶登陸的簡化版功能。最大挑戰是:據說現在的QQ號碼已經有10位數了。
輸入格式:
輸入首先給出一個正整數N(≤105),隨後給出N行指令。每行指令的格式為:“命令符(空格)QQ號碼(空格)密碼”。其中命令符為“N”(代表New)時表示要新申請一個QQ號,後面是新帳戶的號碼和密碼;命令符為“L”(代表Login)時表示是老帳戶登陸,後面是登陸資訊。QQ號碼為一個不超過10位、但大於1000(據說QQ老總的號碼是1001)的整數。密碼為不小於6位、不超過16位、且不包含空格的字串。
輸出格式:
針對每條指令,給出相應的資訊:
1)若新申請帳戶成功,則輸出“New: OK”;
2)若新申請的號碼已經存在,則輸出“ERROR: Exist”;
3)若老帳戶登陸成功,則輸出“Login: OK”;
4)若老帳戶QQ號碼不存在,則輸出“ERROR: Not Exist”;
5)若老帳戶密碼錯誤,則輸出“ERROR: Wrong PW”。
輸入樣例:
5
L 1234567890 [email protected]
N 1234567890 [email protected]
N 1234567890 [email protected]
L 1234567890 [email protected]
L 1234567890 [email protected]
輸出樣例:
ERROR: Not Exist
New: OK
ERROR: Exist
ERROR: Wrong PW
Login: OK
針對不同的情況進行判斷就可以
#include<iostream>
#include <map>
#include<cstring>
#include<string>
using namespace std;
int main(){
int n;
string s,a,b;
map<string,string> mp;
scanf("%d",&n);
while(n--){
cin>>s;
if(s=="N"){
cin>>a>>b;
//if(mp.find(a)!=mp.end())
if(!mp[a].empty())
cout<< "ERROR: Exist"<<endl;
else {
mp[a]=b;
cout<<"New: OK"<<endl;
}
}
else if(s=="L"){
cin>>a>>b;
//if(mp.find(a)!=mp.end()){
if(!mp[a].empty()){
if(mp[a]==b) cout<<"Login: OK"<<endl;
else cout<<"ERROR: Wrong PW"<<endl;
}
else cout<<"ERROR: Not Exist"<<endl;
}
}
return 0;
}