import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
{
//проверяем, есть ли такой пользователь
if(usersAndPasswords.containsKey(username)){
//если есть, то мы не можем добавить нового с таким же именем
return "fail: user already exists";
} else {
//если нет, то добавляем нового пользователя
usersAndPasswords.put(username, password);
return "success: new user added";
}
}
{
//проверяем, зарегистрирован ли такой пользователь
if(usersAndPasswords.containsKey(username)){
//проверяем, совпадает ли зарегистрированный пароль с введенным паролем
if (usersAndPasswords.get(username).equals(password)){
//проверяем, есть ли такой пользователь в списке вошедших пользователей
if(loggedInUsers.containsKey(username)) {
return "fail: already logged in";
} else {
loggedInUsers.put(username,1);
return "success: user logged in";
}
} else return "fail: incorrect password";
} else return "fail: no such user";
}
public static String logout
(String username, HashMap
< String, String
> usersAndPasswords, HashMap
< String, Integer
> loggedInUsers
) {
//проверяем, зарегистрирован ли такой пользователь
if(usersAndPasswords.containsKey(username)){
//проверяем, есть ли пользователь в списке вошедших
if(loggedInUsers.containsKey(username)) {
//если есть, то удаляем его
loggedInUsers.remove(username);
return "success: user logged out";
} else return "fail: already logged out";
} else return "fail: no such user";
}
public static void main
(String[] args
) {
Scanner sc
= new Scanner
(System.
in); int n;
n = sc.nextInt();
//список зарегистрированных пользователей и их пароли
HashMap
< String, String
> usersAndPasswords
= new HashMap
< String, String
>(); //список вошедших пользователей
HashMap
< String, Integer
> loggedInUsers
= new HashMap
< String, Integer
>(); for(int i = 0; i < n; i++) {
command = sc.next();
if(command.equals("register")) {
username = sc.next();
password = sc.next();
System.
out.
println(register
(username, password, usersAndPasswords
)); } else if(command.equals("login")){
username = sc.next();
password = sc.next();
System.
out.
println(login
(username, password, usersAndPasswords, loggedInUsers
)); } else if(command.equals("logout")){
username = sc.next();
System.
out.
println(logout
(username, usersAndPasswords, loggedInUsers
)); }
}
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CiAKcHVibGljIGNsYXNzIE1haW4KewoJ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