{"id":588,"date":"2015-12-28T00:01:59","date_gmt":"2015-12-27T21:01:59","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=588"},"modified":"2015-12-28T01:16:23","modified_gmt":"2015-12-27T22:16:23","slug":"timus-%e2%84%962002","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=588","title":{"rendered":"Timus \u21162002"},"content":{"rendered":"<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"http:\/\/acm.timus.ru\/problem.aspx?space=1&amp;num=2002\" target=\"_blank\">\u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<p>\u0422\u0435\u0441\u0442:<\/p>\n<table>\n<tbody>\n<tr>\n<td>\u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/td>\n<td>\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>register alena 223344<\/td>\n<td>success: new user added<\/td>\n<\/tr>\n<tr>\n<td>login alena 223<\/td>\n<td>fail: incorrect password<\/td>\n<\/tr>\n<tr>\n<td>login alena 223344<\/td>\n<td>success: user logged in<\/td>\n<\/tr>\n<tr>\n<td>login john 454545<\/td>\n<td>fail: no such user<\/td>\n<\/tr>\n<tr>\n<td>logout alena<\/td>\n<td>success: user logged out<\/td>\n<\/tr>\n<tr>\n<td>logout alena<\/td>\n<td>fail: already logged out<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u0420\u0435\u0448\u0435\u043d\u0438\u0435:<\/p>\n<pre class=\"lang:java decode:true\">import java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\n \r\npublic class Main\r\n{\r\n\tpublic static String register(String username, String password, HashMap&lt; String, String&gt; usersAndPasswords)\r\n\t{\r\n\t\t\/\/\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\r\n\t\tif(usersAndPasswords.containsKey(username)){\r\n\t\t\t\/\/\u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c, \u0442\u043e \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u043e\u0433\u043e \u0441 \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u0438\u043c\u0435\u043d\u0435\u043c\r\n\t\t\treturn \"fail: user already exists\";\r\n\t\t} else {\r\n\t\t\t\/\/\u0435\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\r\n\t\t\tusersAndPasswords.put(username, password);\r\n\t\t\treturn \"success: new user added\";\r\n\t\t}\r\n\t}\r\n\tpublic static String login(String username, String password, HashMap&lt; String, String&gt; usersAndPasswords, HashMap&lt; String, Integer&gt; loggedInUsers)\r\n\t{\r\n\t\t\/\/\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\r\n\t\tif(usersAndPasswords.containsKey(username)){\r\n\t\t\t\/\/\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u043b\u0438 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u0430\u0440\u043e\u043b\u044c \u0441 \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u043c \u043f\u0430\u0440\u043e\u043b\u0435\u043c\r\n\t\t\tif (usersAndPasswords.get(username).equals(password)){\r\n\t\t\t\t\/\/\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0432\u043e\u0448\u0435\u0434\u0448\u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439\r\n\t\t\t\tif(loggedInUsers.containsKey(username)) {\r\n\t\t\t\t\treturn \"fail: already logged in\";\r\n\t\t\t\t} else { \r\n\t\t\t\t\tloggedInUsers.put(username,1);\r\n\t\t\t\t\treturn \"success: user logged in\";\r\n\t\t\t\t}\r\n\t\t\t} else return \"fail: incorrect password\";\r\n\t\t} else return \"fail: no such user\";\r\n\t}\r\n\tpublic static String logout(String username, HashMap&lt; String, String&gt; usersAndPasswords, HashMap&lt; String, Integer&gt; loggedInUsers)\r\n\t{\r\n\t\t\/\/\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\r\n\t\tif(usersAndPasswords.containsKey(username)){\r\n\t\t\t\/\/\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0435\u0441\u0442\u044c \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0432\u043e\u0448\u0435\u0434\u0448\u0438\u0445\r\n\t\t\tif(loggedInUsers.containsKey(username)) {\r\n\t\t\t\t\/\/\u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c, \u0442\u043e \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0435\u0433\u043e\r\n\t\t\t\tloggedInUsers.remove(username);\r\n\t\t\t\treturn \"success: user logged out\";\r\n\t\t\t} else return \"fail: already logged out\";\r\n\t\t} else return \"fail: no such user\";\r\n\t}\r\n\tpublic static void main (String[] args)\r\n\t{\r\n\t\tScanner sc = new Scanner(System.in);\r\n\t\tint n;\r\n\t\tn = sc.nextInt();\r\n\t\t\/\/\u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0438\u0445 \u043f\u0430\u0440\u043e\u043b\u0438\r\n\t\tHashMap&lt; String, String&gt; usersAndPasswords = new HashMap&lt; String, String&gt;();\r\n\t\t\/\/\u0441\u043f\u0438\u0441\u043e\u043a \u0432\u043e\u0448\u0435\u0434\u0448\u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439\r\n\t\tHashMap&lt; String, Integer&gt; loggedInUsers = new HashMap&lt; String, Integer&gt;();\r\n\t\tString command;\r\n\t\tString username;\r\n\t\tString password;\r\n\t\tfor(int i = 0; i &lt; n; i++) {\r\n\t\t\tcommand = sc.next();\r\n\t\t\tif(command.equals(\"register\")) {\r\n\t\t\t\tusername = sc.next();\r\n\t\t\t\tpassword = sc.next();\r\n\t\t\t\tSystem.out.println(register(username, password, usersAndPasswords));\r\n\t\t\t} else if(command.equals(\"login\")){\r\n\t\t\t\tusername = sc.next();\r\n\t\t\t\tpassword = sc.next();\r\n\t\t\t\tSystem.out.println(login(username, password, usersAndPasswords, loggedInUsers));\r\n\t\t\t} else if(command.equals(\"logout\")){\r\n\t\t\t\tusername = sc.next();\r\n\t\t\t\tSystem.out.println(logout(username, usersAndPasswords, loggedInUsers));\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<p>\u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430 \u0434\u0432\u0430 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u041f\u0435\u0440\u0432\u044b\u0439 (usersAndPasswords) \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0430 \u0438\u043c\u044f \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f &#8212; \u043f\u0430\u0440\u043e\u043b\u044c \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f; \u0432\u0442\u043e\u0440\u043e\u0439 (loggedInUsers) \u0445\u0440\u0430\u043d\u0438\u0442 \u0432\u043e\u0448\u0435\u0434\u0448\u0438\u0445 \u043d\u0430 \u0444\u043e\u0440\u0443\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043c\u044b \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043d\u0430\u043c \u0432\u0430\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u0442\u044c \u043b\u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u044d\u0442\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0438\u043b\u0438 \u043d\u0435\u0442.<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0444\u043e\u0440\u0443\u043c \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0438\u043c\u044f \u043a\u0430\u043a \u043a\u043b\u044e\u0447 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u00a0loggedInUsers. \u0410 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u043c\u044b \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0435\u0441\u0442\u044c \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0444\u043e\u0440\u0443\u043c\u0435 \u0438\u043b\u0438 \u043e\u043d \u0443\u0436\u0435 \u0432\u044b\u0448\u0435\u043b, \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0435\u0441\u0442\u044c \u043b\u0438 \u043e\u043d \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 loggedInUsers \u0438\u043b\u0438 \u043d\u0435\u0442\u0443.<\/p>\n<p><a href=\"http:\/\/ideone.com\/5bYAPW\" target=\"_blank\">\u0421\u0441\u044b\u043b\u043a\u0430<\/a> \u043d\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 ideone.<\/p>\n<p><a href=\"http:\/\/acm.timus.ru\/status.aspx?author=171908&amp;status=accepted\" target=\"_blank\">\u0421\u0441\u044b\u043b\u043a\u0430<\/a> \u043d\u0430 \u0437\u0430\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430 http:\/\/acm.timus.ru\/.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435. \u0422\u0435\u0441\u0442: \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 6 register alena 223344 success: new user added login alena 223 fail: incorrect password login alena 223344 success: user logged in login john 454545 fail: no such user logout alena success: user logged out logout alena fail: already logged out \u0420\u0435\u0448\u0435\u043d\u0438\u0435: import java.util.*; &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=588\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":43,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[40,53],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/588"}],"collection":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/users\/43"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=588"}],"version-history":[{"count":1,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/588\/revisions"}],"predecessor-version":[{"id":589,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/588\/revisions\/589"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}