实现QQ新帐户申请和老帐户登陆的简化版功能。最大挑战是:据说现在的QQ号码已经有10位数了。
输入格式:
输入首先给出一个正整数N(≤10^5 ),随后给出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 myQQ@qq.com
N 1234567890 myQQ@qq.com
N 1234567890 myQQ@qq.com
L 1234567890 myQQ@qq
L 1234567890 myQQ@qq.com
输出样例:
ERROR: Not Exist
New: OK
ERROR: Exist
ERROR: Wrong PW
测试点1 答案正确 10/10 10 1 sample 全部5种输出信息
测试点2 答案正确 7/7 691 18 最大表,全部是新申请,密码全部16位
测试点3 答案正确 8/8 439 10 N和L指令各一半,随机交错。帐号随机,取到上下界。密码随机,取到上下界
测试点1 答案正确 10/10 2 1 sample 全部5种输出信息
测试点2 答案正确 7/7 105 14 最大表,全部是新申请,密码全部16位
测试点3 答案正确 8/8 157 11 N和L指令各一半,随机交错。帐号随机,取到上下界。密码随机,取到上下界
输入格式:
输入首先给出一个正整数N(≤10^5 ),随后给出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 myQQ@qq.com
N 1234567890 myQQ@qq.com
N 1234567890 myQQ@qq.com
L 1234567890 myQQ@qq
L 1234567890 myQQ@qq.com
输出样例:
ERROR: Not Exist
New: OK
ERROR: Exist
ERROR: Wrong PW
Login: OK
#include <iostream>
#include <map>
#include <utility>
#include <cctype>
#include <string>
using namespace std;
int main() {
int i, n;
char ch;
char account[11], password[17];
map<string, string> m;
scanf("%d", &n);
while (n--) {
ch = getchar();
while(isspace(ch))
ch = getchar();
scanf("%s%s", account, password);
if (ch == 'N') {
auto p = m.insert(make_pair(account, password));
if (!p.second)
printf("ERROR: Exist\n");
else printf("New: OK\n");
}
else {
auto it = m.find(account);
if (it == m.end())
printf("ERROR: Not Exist\n");
else if (it->second == password)
printf("Login: OK\n");
else printf("ERROR: Wrong PW\n");
}
}
}
测试点1 答案正确 10/10 10 1 sample 全部5种输出信息
测试点2 答案正确 7/7 691 18 最大表,全部是新申请,密码全部16位
测试点3 答案正确 8/8 439 10 N和L指令各一半,随机交错。帐号随机,取到上下界。密码随机,取到上下界
用时比较长,于是把string改成了char*
#include <iostream>
#include <map>
#include <utility>
#include <cctype>
#include <cstring>
using namespace std;
struct ptrcmp {
bool operator()(const char *a, const char *b)const {
return strcmp(a, b) < 0;
}
};
int main() {
int n;
char ch;
char *account, *password;
map<char*,char*,ptrcmp> m;
scanf("%d", &n);
while (n--) {
account = new char[11];
password = new char[17];
ch = getchar();
while(isspace(ch))
ch = getchar();
scanf("%s%s", account, password);
if (ch == 'N') {
auto p = m.insert(make_pair(account, password));
if (!p.second)
printf("ERROR: Exist\n");
else printf("New: OK\n");
}
else {
auto it = m.find(account);
if (it == m.end())
printf("ERROR: Not Exist\n");
else if (strcmp(it->second, password) == 0)
printf("Login: OK\n", it->second);
else printf("ERROR: Wrong PW\n");
}
}
}
测试点1 答案正确 10/10 2 1 sample 全部5种输出信息
测试点2 答案正确 7/7 105 14 最大表,全部是新申请,密码全部16位
测试点3 答案正确 8/8 157 11 N和L指令各一半,随机交错。帐号随机,取到上下界。密码随机,取到上下界
比原来快了一些