zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    [翻译]AxureBasic Interactions原型设计工具Axure学习第1.3节
    [翻译]AxurePage Properties原型设计工具Axure学习第1.2节
    更新数据库表的某一字段为限制范围的随机数
    silverlight带水印的自定义TextBox控件(版本2)
    silverlight带水印的TextBox
    [翻译]AxureMasters原型设计工具Axure学习第2.2节
    [翻译]AxureBuild Wireframes原型设计工具Axure学习第1.1节
    [翻译]Windows Phone(Silverlight) 控件数据绑定
    [翻译]AxureDynamic Panel(Basic)原型设计工具Axure学习第2.1节
    假如你是新浪微博移动方向的产品经理
  • 原文地址:https://www.cnblogs.com/keyboarder-zsq/p/5934474.html
Copyright © 2011-2022 走看看