STL map的使用(红黑树)
// QQ帐户的申请与登陆.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <stdio.h>
#include <map>
#include <string>
using namespace std;
map<int,string> cmap;
int _tmain(int argc, _TCHAR* argv[])
{
int n;
scanf("%d", &n);
while(n--){
char cmdLine[3];
int id;
char pwd[20];
scanf("%s%d%s", cmdLine, &id, pwd);
string sstr = pwd;
if(cmdLine[0] == 'N'){
if(cmap.find(id) == cmap.end()){
cmap[id] = sstr;
printf("New: OK\n");
}
else{
printf("ERROR: Exist\n");
}
}
else{
if(cmap.find(id) == cmap.end())
printf("ERROR: Not Exist\n");
else{
if(sstr != cmap[id])
printf("ERROR: Wrong PW\n");
else
printf("Login: OK\n");
}
}
}
return 0;
}