{"id":474,"date":"2015-12-16T17:06:07","date_gmt":"2015-12-16T14:06:07","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=474"},"modified":"2015-12-21T00:21:04","modified_gmt":"2015-12-20T21:21:04","slug":"timus-2002","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=474","title":{"rendered":"Timus 2002"},"content":{"rendered":"<p>\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 <a href=\"http:\/\/acm.timus.ru\/status.aspx?space=1&amp;num=2002&amp;author=me\">\u0437\u0430\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/a>.<\/p>\n<p>\u0418\u0434\u0435\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c 2 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0430 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u043d \u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u0430 \u0432\u0442\u043e\u0440\u043e\u0439 &#8212; \u043b\u043e\u0433\u0438\u043d \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 (\u043e\u043d\u043b\u0430\u0439\u043d\/\u043e\u0444\u0444\u043b\u0430\u0439\u043d).<\/p>\n<p>\u041d\u0430 \u0421++ \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u043e\u0434\u043d\u0438\u043c \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439: map&lt;string, pair&lt;string, bool&gt; &gt; m.<\/p>\n<p>\u041a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b (<a href=\"http:\/\/ideone.com\/3Uqhuh\">http:\/\/ideone.com\/3Uqhuh<\/a>):<\/p>\n<pre class=\"lang:java decode:true\">import java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\n\r\nclass Ideone {\r\n\tpublic static void main (String[] args) {\r\n\t\tMap&lt;String, String&gt; m = new HashMap&lt;String, String&gt;();\r\n\t\tMap&lt;String, Boolean&gt; u = new HashMap&lt;String, Boolean&gt;();\r\n\t\tScanner in = new Scanner(System.in);\r\n\t\tint n = in.nextInt();\r\n\t\tString s;\r\n\t\tfor(int i = 0; i &lt; n; i++) {\r\n\t\t\ts = in.next();\r\n\t\t\tif (s.equals(\"register\")) {\r\n\t\t\t\tString a, b;\r\n\t\t\t\ta = in.next();\r\n\t\t\t\tb = in.next();\r\n\t\t\t\tif (m.containsKey(a)) {\r\n\t\t\t\t\tSystem.out.println(\"fail: user already exists\");\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tm.put(a, b);\r\n\t\t\t\t\tu.put(a, false);\r\n\t\t\t\t\tSystem.out.println(\"success: new user added\");\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse if (s.equals(\"login\")) {\r\n\t\t\t\tString a, b;\r\n\t\t\t\ta = in.next();\r\n\t\t\t\tb = in.next();\r\n\t\t\t\tif (!m.containsKey(a)) {\r\n\t\t\t\t\tSystem.out.println(\"fail: no such user\");\r\n\t\t\t\t}\r\n\t\t\t\telse if (!b.equals(m.get(a))) {\r\n\t\t\t\t\tSystem.out.println(\"fail: incorrect password\");\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tif (u.get(a) == false) {\r\n\t\t\t\t\t\tu.put(a, true);\r\n\t\t\t\t\t\tSystem.out.println(\"success: user logged in\");\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse {\r\n\t\t\t\t\t\tSystem.out.println(\"fail: already logged in\");\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tString a;\r\n\t\t\t\ta = in.next();\r\n\t\t\t\tif (!m.containsKey(a)) {\r\n\t\t\t\t\tSystem.out.println(\"fail: no such user\");\r\n\t\t\t\t}\r\n\t\t\t\telse {\r\n\t\t\t\t\tif (u.get(a) == true) {\r\n\t\t\t\t\t\tu.put(a, false);\r\n\t\t\t\t\t\tSystem.out.println(\"success: user logged out\");\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse {\r\n\t\t\t\t\t\tSystem.out.println(\"fail: already logged out\");\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0437\u0430\u0441\u0447\u0438\u0442\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0418\u0434\u0435\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c 2 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0430 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u043d \u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u0430 \u0432\u0442\u043e\u0440\u043e\u0439 &#8212; \u043b\u043e\u0433\u0438\u043d \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 (\u043e\u043d\u043b\u0430\u0439\u043d\/\u043e\u0444\u0444\u043b\u0430\u0439\u043d). \u041d\u0430 \u0421++ \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u043e\u0434\u043d\u0438\u043c \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c, \u0435\u0441\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439: map&lt;string, pair&lt;string, bool&gt; &gt; m. \u041a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b (http:\/\/ideone.com\/3Uqhuh): import &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=474\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[40,54,53],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/474"}],"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\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=474"}],"version-history":[{"count":1,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/474\/revisions"}],"predecessor-version":[{"id":475,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/474\/revisions\/475"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}