#P1665. 2024.1.30-YMX-后端开发机试-第二题

2024.1.30-YMX-后端开发机试-第二题

As an intern at Amazon, you have been assigned a task to implement the sign-in pages inthe Amazon Dummy Website. There are three sign-in pages, each with its own APl:

Register Login Logout
Function Registers a newuser with the username and password Verifies the username and password, then grants or denies access username logs out of the website
API Request register <username> <password> login <username> <password> logout <username>
Returns 1.lf the registrationwas successful,Registered Successfully 2.lf the user
already exists,Username
already exists
1.lf the login was successful, Logged In Successfully
2.If the login was
unsuccessful,Login
Unsuccessful
lf the logout was successful, Logged Out
Successfully
lf the given
username wasn't logged in, Logout
Unsuccessful

Given a log of APl requests, return the list of returns from the mock website.

Notes: 1.Initially, there are no users registered. 2.lf a user is already logged in and makes a login request, the new request is unsuccessful.The original login remains active. 3.Each log is an APl request and is in one of the three allowed formats. 4.The order of execution of each request is the same as the order of input. 5.The usernames and passwords are case-sensitive.

Example

The website receives the following APl requests in order: 1.register user5 qwerty

​ A new user with the username "user05" is registered to the website with the password"qwerty". The return value is Registered Successfully 2.login user05 qwerty ​ There is a user with that username. ​ The password matches that user's password ​ The user is not already logged in. ​ The login is successful and the return value is Logged In Successfully

3.logout user05 The user with username "user05" is currently logged in. The logout is successful and the return value is Logged Out Successfully

Constraints

1n1e51 \leq n \leq 1e5

1username,password101 \leq |username| , |password| \leq 10(wheres|s| is the length of string ss)

username and password are alphanumeric strings , ranges [0-9,a-z,A-Z]

输入输出描述补充

输入第一行一个数n,代表记录个数

接下来n行,每行是{register,login,logout} 其中的一个为开头。API格式符合上述表格描述

你需要输出n行结果。具体见以下两个Sample

Sample Case 0

Sample Input

5
register david david123
register adam lAdaml
login david david123
login adam ladam1
logout david

Sample Output

Registered Successfully
Registered Successfully
Logged In Successfully
Login Unsuccessful
Logged 0ut Successfully

Explanation 1.register david david123: There is no user with the username "david" relistered, so the registration is successful. 2.register adam 1Adaml: There is no user with the username "adam" registered, so theregistration is successful. 3.login david david123: The username and the password for the user match with thatin the database, so the login is successful. 4.login adam ladam1: The password ("1adam1") does not match the actual password("1Adam1"), so the login is unsuccessful. 5.logout david: The user "david" is logged in currently, so the logout is successful

Sample Case 1

Sample Input

4
login harry 12345678
register harry 12345678
logout harry
register harry harrycool

Sample Output

Login Unsuccessful
Registered Successfully
Logout Unsuccessful
Username already exists

1.login harry 12345678: There is no username "harry" registered so the login is unsuccessful

2.register harry 12345678: There is no username "harry" registered so the registration is successful.

3.logout harry: There is no username "harry" logged in so the logout is unsuccessful

4.register harry harrycool:There is already a username "harry" so the registration is unsuccessful.