zoukankan      html  css  js  c++  java
  • 7-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 (≤) - 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


    用c++的map
    代码:
    #include <cstdio>
    #include <map>
    using namespace std;
    map<string,string> mp;
    int main() {
        int n;
        char op[2],no[11],pw[17];
        scanf("%d",&n);
        for(int i = 0;i < n;i ++) {
            scanf("%s%s%s",op,no,pw);
            if(op[0] == 'R') {
                if(mp[no] != "") printf("ERROR: Account Number Already Exists
    ");
                else {
                    mp[no] = pw;
                    printf("Register Successful
    ");
                }
            }
            else {
                if(mp[no] == "") printf("ERROR: Account Not Exist
    ");
                else if(mp[no] != pw) printf("ERROR: Wrong Password
    ");
                else printf("Log in Successful
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    2017-2018-1 课表
    所编裴书练习参考解答封面 [购买了书的同志记得一定要邮件联系, 并加我微信, 方便更正错误. 这里更新有时会慢, 或者懒得弄.]
    人工智能图片放大
    猜15个名人
    Excel 当前行高亮
    2014年至今的博文目录(更新至2019年1月7日,2017篇)
    拓扑学中凝聚点的几个等价定义
    江苏省2017年高等数学竞赛本二试题(含解答)
    裴礼文数学分析中的典型问题与方法第4章一元函数积分学练习
    2017年华东师范大学数学竞赛(数学类)试题
  • 原文地址:https://www.cnblogs.com/8023spz/p/12266762.html
Copyright © 2011-2022 走看看