it was an ordinary grim october morning. the sky was covered by heavy gray clouds. it was a little rainy. the rain drops fell on the windows with quiet bangs. ilya was sitting at the computer and gloomy
looking out of the window at the bleak scenery. suddenly, a note caught his attention from the lower right corner of the screen. it said: “you have 1 unread email message(s)”. the boy braced himself for a bit of useless spam and opened the letter. but it turned
out much more interesting...
dear sir, you have received this message from the “rutnok bks” hr department!
we have received your application for a software developer and we found your cv quite interesting. we would like to suggest a simple test task to evaluate your professional skills. your task is to implement
the register system for a forum. it must support three types of operations:
“register username password”: to register a new user with name “username” and password “password”. if such user already exists in the database, the system should output the error message “fail: user already exists”. otherwise, it should output message “success:
new user added”.
“login username password”: to log into the system as user “username” with password “password”. if such user does not exist, the system should output “fail: no such user”. otherwise, if the user enters an incorrect password, the system should output “fail:
incorrect password”. otherwise, if the user is already logged in the system at that moment, it should output “fail: already logged in”. otherwise, it should output “success: user logged in”.
“logout username”: to log out of the system as user “username”. if such user does not exist, the system should output “fail: no such user”. otherwise, if the user isn’t in the system at that moment, it should output “fail: already logged out”. otherwise,
it should output “success: user logged out”.
use this letter as a formal description of the algorithm and follow the described format of system messages. good luck!
ilya stopped doing anything else and started solving the test task. you can try to solve it as well!
the first line contains an integer n that is the number of operations (1 ≤ n ≤ 100). each of the next n lines contains a single query in the format given above. we can assume
that “username” and “password” are non-empty strings with length of up to 30 characters. all characters in these strings have codes from 33 to 126.
for each operation, print the message on a single line in the format given above. be sure to put spaces and punctuation marks in the right places in the messages.
input
output
實作一個登陸系統。
思路:
1 使用map,在map中的就是已經注冊的了
2 使用資料結構儲存使用者名,是否登陸和密碼
3 使用if else判斷處理第一個字元串-指令
類似很多人都寫的什麼圖書館管理系統,什麼資訊系統之類的登陸控制管理,都是很簡單的東西,一步一步寫就不會錯了,完成速度相當于打字速度。