下面是C++STl map的实现;
#include<bits/stdc++.h>
using namespace std;
map<string,string>q; //构造一个map类,为了简单处理,笔者将容器内的存储对象定义为两个string类
void login(string a,string p); //定义一个登陆函数
void apply(string a,string p); //定义一个申请函数
void login(string a,string p)
{
map<string,string> :: iterator s;//定义一个对应两个string类对象的map迭代器
s = q.find(a); //对map进行查找
if(s != q.end() && p == s -> second) //若找到且密码相等,提示登陆成功
{
printf("Login: OK");
}
else if(s != q.end() && p != s -> second) //若存在但密码不等,提示失败
{
printf("ERROR: Wrong PW");
}
else if(s == q.end()) //若查找失败,则提示不存在
{
printf("ERROR: Not Exist");
}
}
void apply(string a,string p)
{
map<string,string> :: iterator s;
s = q.find(a);
if(s != q.end()) //若查找成功,则提示账户已存在
{
printf("ERROR: Exist");
}
else //若查找失败,则将该账户作为新元素插入map中
{
q.insert(pair<string,string>(a,p));
printf("New: OK");
}
}
int main(void)
{
int i = 0,n = 0;
string account,password,temp,temp2,choose;
scanf("%d",&n);
map<string,string> :: iterator s;
for(i = 0;i < n;i++)
{
cin >> choose;
cin >> temp;
cin >> temp2;
if(choose == "L")
{
login(temp,temp2);
}
else
{
apply(temp,temp2);
}
if(i != n - 1)
{
printf("\n");
}
}
return 0;
}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-86698-2.html
濒海战斗舰也就是反恐和特种作战用的
标准化和模块化的优势需要量积累