AmazonOA #333
Sign In Pages
估计简单可在线判题
考点(AI 标注)模拟/实现哈希计数
Implement the endpoints of three sign-in pages: Register, Login and Logout. Process n requests in order and output the return value of each request.
register username password: if the username is not registered, create the user and return Registered Successfully (registering does not log the user in); if the username already exists, return Username already exists, leaving the existing password and login state unchanged. login username password: if the user exists, the password matches and the user is not currently logged in, the login succeeds and returns Logged In Successfully; otherwise return Login Unsuccessful. A logged-in user who logs in again always fails, and the original session stays active. logout username: if the user is currently logged in, log them out and return Logged Out Successfully; if the user does not exist or is not logged in, return Logout Unsuccessful.
Initially there are no users. Requests are executed in input order. Usernames and passwords are case-sensitive, users do not affect each other's state, and a failed request changes no state.
输入格式
The first line contains n. Each of the next n lines contains one request: register username password, login username password, or logout username, with fields separated by a single space. 1≤n≤10^6; username and password are alphanumeric strings (0-9, a-z, A-Z) of length 1..10.
输出格式
Output n lines; line i is the return value of request i, which is one of Registered Successfully, Username already exists, Logged In Successfully, Login Unsuccessful, Logged Out Successfully, Logout Unsuccessful.
样例 1
输入:
5
register david david123
register adam 1Adam1
login david david123
login adam 1adam1
logout david
输出:
Registered Successfully
Registered Successfully
Logged In Successfully
Login Unsuccessful
Logged Out Successfully
样例 2
输入:
8
register Bob pw1
register Bob pw2
login Bob pw2
login Bob pw1
login Bob pw1
logout bob
logout Bob
logout Bob
输出:
Registered Successfully
Username already exists
Login Unsuccessful
Logged In Successfully
Login Unsuccessful
Logout Unsuccessful
Logged Out Successfully
Logout Unsuccessful
样例 3
输入:
5
login ghost pw
logout ghost
register ghost pw
logout ghost
login ghost pw
输出:
Login Unsuccessful
Logout Unsuccessful
Registered Successfully
Logout Unsuccessful
Logged In Successfully
样例说明
Example 1: david and adam register successfully; david logs in with the correct password; adam's password 1adam1 differs in case from 1Adam1 used at registration, so the login fails; david is logged in, so the logout succeeds. Example 2: Bob's repeated registration fails and does not overwrite the password; logging in with pw2 fails and with pw1 succeeds; logging in again while logged in fails; logout bob fails because of the different case, then Bob logs out successfully, and logging out again fails. Example 3: an unregistered user fails both to log in and to log out; a user who has just registered but has not logged in fails to log out.