PTA QQ Account Manageme【map的巧妙应有】

5-27 QQ Account Management (25分)

You are supposed to implement the functions of account “Log in” and “Register” for the most popular instant messager QQ. The most challenging part is that QQ now has more than a billion users.

Input Specification:

Each input file contains one test case. For each case, the first line contains an integer N (≤105le 10^5≤10
​5
​​) - the total number of queries. Then N lines follow, each contains a query in the format Command QQ_No Password where Command is either R (meaning to register a new account, and hence followed by a new account number and a password), or L (meaning to log in with an existing account, and hence followed by the account number and the password); QQ_No is an integer that is greater than 1000 and no more than 10 digits long; and Password is a string with no less than 6 and no more than 16 characters without any space.

Output Specification:

For each test case, print the corresponding message for each query in a line. The messages are:
•If a new account is successfully registered, output “Register Successful”;
•If the new registering account number already exists, output “ERROR: Account Number Already Exists”;
•If log in successfully, output “Log in Successful”;
•If the log in account does not exist, output “ERROR: Account Not Exist”;
•If log in with a wrong password, output “ERROR: Wrong Password”.

Sample Input:
5
L 1234567890 myQQ@qq.com
R 1234567890 myQQ@qq.com
R 1234567890 myQQ@qq.com
L 1234567890 myQQ@qq
L 1234567890 myQQ@qq.com

Sample Output:
ERROR: Account Not Exist
Register Successful
ERROR: Account Number Already Exists
ERROR: Wrong Password
Log in Successful

这是队友的巧用map
用一个数组记录编号,然后编号映射到输入的i,输入的邮箱直接是用二位数组记录的,然后数组记录的编号映射到的 i ,直接是二维数组中的 i ,非常棒。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
const double eps=1e-5;
const double pi=acos(-1.0);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
#define MAX 100010

int n,m;
char c1;
char pass[MAX][21];
ll a[MAX];
int main()
{
    map < ll, int >q;
    int t,i,j,k;
    scanf("%d",&n);
    getchar();
    int num1=0;
    for(i=1; i<=n; i++)
    {
        ll b;
        int flag=0;
        scanf("%c",&c1);
        scanf("%lld%s",&a[i],pass[i]);
        getchar();
        if(c1=='R')
        {
            if(q[a[i]]>0)
                printf("ERROR: Account Number Already Exists
");
            else
            {
                printf("Register Successful
");
                q[a[i]]=i;
            }
        }
        if(c1=='L')
        {
            if(a[q[a[i]]]==a[i])
            {
                if(strcmp(pass[q[a[i]]],pass[i])==0)
                    printf("Log in Successful
");
                else
                    printf("ERROR: Wrong Password
");
            }
            else if(a[q[a[i]]]==0)
                printf("ERROR: Account No`
 Exist
");
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/keyboarder-zsq/p/5934474.html