ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 2002. Test Task

JAVA, plz help
Posted by fletcher6847 11 Nov 2016 12:58

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Timus2002 {

    public static void main(String[] args) {

        Map<String, String> map = new HashMap<>();
        Scanner sc = new Scanner(System.in);
        String[] s = new String[105];
        ArrayList<String> logged = new ArrayList<>();
        int n = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextLine();
        }

        for (int i = 0; i < n; i++) {
            String[] mas = s[i].split(" ");
            if(mas[0].equals("register")){
                if(map.containsKey(mas[1])){
                    System.out.println("fail: user already exists");
                    continue;
                }
                map.put(mas[1], mas[2]);
                System.out.println("success: new user added");
            }

            String login = mas[1];
            if(mas[0].equals("login")){
                String pass = mas[2];
                if(!map.containsKey(login)) {
                    System.out.println("fail: no such user");
                    continue;
                }
                String value = map.get(login);
                if(!value.equals(pass))
                    System.out.println("fail: incorrect password");

                if(value.equals(pass)) {
                    if (!logged.contains(login)) {
                        logged.add(login);
                        System.out.println("success: user logged in");
                    }
                    else
                        System.out.println("fail: already logged in");

                }
            }

            if(mas[0].equals("logout")) {
                if (!map.containsKey(login))
                    System.out.println("fail: no such user");
                if (!logged.contains(login))
                    System.out.println("fail: already logged out");
                else {
                    System.out.println("success: user logged out");
                    logged.remove(login);
                }
            }
        }
    }
}
Re: JAVA, plz help
Posted by fletcher6847 11 Nov 2016 13:00
It works, but cant pass the test