{"id":363,"date":"2013-08-04T01:17:41","date_gmt":"2013-08-04T05:17:41","guid":{"rendered":"http:\/\/www.ferociouscoder.com\/blog\/?p=363"},"modified":"2013-08-04T01:17:41","modified_gmt":"2013-08-04T05:17:41","slug":"uva-489-hangman-judge","status":"publish","type":"post","link":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html","title":{"rendered":"UVA 489 &#8211; Hangman Judge"},"content":{"rendered":"<p>Pretty easy problem. The word to guess can be safely put into a HashSet and we can keep guessing until the set is empty or until we are done with (7) guesses that are allowed. One thing to note is that the order of the input matters but duplicates in the input do not matter. Therefore, I use an ArrayList as well as a HashSet to store the input and get AC.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nimport java.io.PrintWriter;\r\nimport java.util.ArrayList;\r\nimport java.util.HashSet;\r\nimport java.util.Scanner;\r\n\r\n\/**\r\n * \r\n * @author Sanchit M. Bhatnagar\r\n * @see http:\/\/uhunt.felix-halim.net\/id\/74004\r\n * \r\n *\/\r\npublic class P489 {\r\n\r\n  public static void main(String&#x5B;] args) {\r\n    Scanner sc = new Scanner(System.in);\r\n    PrintWriter out = new PrintWriter(System.out);\r\n\r\n    while (sc.hasNextInt()) {\r\n      int N = sc.nextInt();\r\n      if (N == -1)\r\n        break;\r\n\r\n      char&#x5B;] word = sc.next().toCharArray();\r\n      HashSet&lt;Character&gt; hax = new HashSet&lt;Character&gt;();\r\n      for (Character c : word) {\r\n        hax.add(c);\r\n      }\r\n\r\n      \/\/ Order Matters\r\n      char&#x5B;] guesses = sc.next().toCharArray();\r\n      ArrayList&lt;Character&gt; hax3 = new ArrayList&lt;Character&gt;();\r\n      HashSet&lt;Character&gt; hax2 = new HashSet&lt;Character&gt;();\r\n      for (Character c : guesses) {\r\n        if (!hax2.contains(c)) {\r\n          hax3.add(c);\r\n        }\r\n        hax2.add(c);\r\n      }\r\n\r\n      int movesLeft = 7;\r\n      for (Character c : hax3) {\r\n        if (hax.contains(c)) {\r\n          hax.remove(c);\r\n        } else {\r\n          movesLeft--;\r\n        }\r\n        if (hax.size() == 0 || movesLeft == 0)\r\n          break;\r\n      }\r\n\r\n      out.println(&quot;Round &quot; + N);\r\n      if (movesLeft &lt; 1) {\r\n        out.println(&quot;You lose.&quot;);\r\n      } else if (hax.size() == 0) {\r\n        out.println(&quot;You win.&quot;);\r\n      } else {\r\n        out.println(&quot;You chickened out.&quot;);\r\n      }\r\n    }\r\n\r\n    out.close();\r\n    sc.close();\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Pretty easy problem. The word to guess can be safely put into a HashSet and we can keep guessing until the set is empty or until we are done with (7) guesses that are allowed. One thing to note is that the order of the input matters but duplicates in the input do not matter. &hellip; <a href=\"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">UVA 489 &#8211; Hangman Judge<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[18,19,17],"tags":[21,20,22],"class_list":["post-363","post","type-post","status-publish","format-standard","hentry","category-competitive-programming-3","category-java","category-uva-online-judge","tag-competitive-programming-3-2","tag-java-2","tag-uva-online-judge-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>UVA 489 - Hangman Judge - Ferocious Coder<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"UVA 489 - Hangman Judge - Ferocious Coder\" \/>\n<meta property=\"og:description\" content=\"Pretty easy problem. The word to guess can be safely put into a HashSet and we can keep guessing until the set is empty or until we are done with (7) guesses that are allowed. One thing to note is that the order of the input matters but duplicates in the input do not matter. &hellip; Continue reading UVA 489 &#8211; Hangman Judge &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html\" \/>\n<meta property=\"og:site_name\" content=\"Ferocious Coder\" \/>\n<meta property=\"article:published_time\" content=\"2013-08-04T05:17:41+00:00\" \/>\n<meta name=\"author\" content=\"Rawrosaur\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rawrosaur\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-489-hangman-judge-363.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-489-hangman-judge-363.html\"},\"author\":{\"name\":\"Rawrosaur\",\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#\\\/schema\\\/person\\\/1fb5cbee546cffd619a7b301e3dc447a\"},\"headline\":\"UVA 489 &#8211; Hangman Judge\",\"datePublished\":\"2013-08-04T05:17:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-489-hangman-judge-363.html\"},\"wordCount\":255,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#\\\/schema\\\/person\\\/1fb5cbee546cffd619a7b301e3dc447a\"},\"keywords\":[\"competitive programming 3\",\"java\",\"uva online judge\"],\"articleSection\":[\"Competitive Programming 3\",\"Java\",\"UVA Online Judge\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-489-hangman-judge-363.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-489-hangman-judge-363.html\",\"url\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-489-hangman-judge-363.html\",\"name\":\"UVA 489 - Hangman Judge - Ferocious Coder\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#website\"},\"datePublished\":\"2013-08-04T05:17:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-489-hangman-judge-363.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-489-hangman-judge-363.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-489-hangman-judge-363.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"UVA 489 &#8211; Hangman Judge\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/\",\"name\":\"Ferocious Coder\",\"description\":\"RAWR!\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#\\\/schema\\\/person\\\/1fb5cbee546cffd619a7b301e3dc447a\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#\\\/schema\\\/person\\\/1fb5cbee546cffd619a7b301e3dc447a\",\"name\":\"Rawrosaur\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg\",\"caption\":\"Rawrosaur\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg\"},\"sameAs\":[\"http:\\\/\\\/www.ferociouscoder.com\\\/\"],\"url\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/author\\\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"UVA 489 - Hangman Judge - Ferocious Coder","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html","og_locale":"en_US","og_type":"article","og_title":"UVA 489 - Hangman Judge - Ferocious Coder","og_description":"Pretty easy problem. The word to guess can be safely put into a HashSet and we can keep guessing until the set is empty or until we are done with (7) guesses that are allowed. One thing to note is that the order of the input matters but duplicates in the input do not matter. &hellip; Continue reading UVA 489 &#8211; Hangman Judge &rarr;","og_url":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html","og_site_name":"Ferocious Coder","article_published_time":"2013-08-04T05:17:41+00:00","author":"Rawrosaur","twitter_misc":{"Written by":"Rawrosaur","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html#article","isPartOf":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html"},"author":{"name":"Rawrosaur","@id":"https:\/\/www.ferociouscoder.com\/blog\/#\/schema\/person\/1fb5cbee546cffd619a7b301e3dc447a"},"headline":"UVA 489 &#8211; Hangman Judge","datePublished":"2013-08-04T05:17:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html"},"wordCount":255,"commentCount":0,"publisher":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/#\/schema\/person\/1fb5cbee546cffd619a7b301e3dc447a"},"keywords":["competitive programming 3","java","uva online judge"],"articleSection":["Competitive Programming 3","Java","UVA Online Judge"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html","url":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html","name":"UVA 489 - Hangman Judge - Ferocious Coder","isPartOf":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/#website"},"datePublished":"2013-08-04T05:17:41+00:00","breadcrumb":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-489-hangman-judge-363.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.ferociouscoder.com\/blog"},{"@type":"ListItem","position":2,"name":"UVA 489 &#8211; Hangman Judge"}]},{"@type":"WebSite","@id":"https:\/\/www.ferociouscoder.com\/blog\/#website","url":"https:\/\/www.ferociouscoder.com\/blog\/","name":"Ferocious Coder","description":"RAWR!","publisher":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/#\/schema\/person\/1fb5cbee546cffd619a7b301e3dc447a"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.ferociouscoder.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.ferociouscoder.com\/blog\/#\/schema\/person\/1fb5cbee546cffd619a7b301e3dc447a","name":"Rawrosaur","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg","caption":"Rawrosaur"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg"},"sameAs":["http:\/\/www.ferociouscoder.com\/"],"url":"https:\/\/www.ferociouscoder.com\/blog\/archives\/author\/admin"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1mYMV-5R","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/posts\/363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/comments?post=363"}],"version-history":[{"count":1,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/posts\/363\/revisions"}],"predecessor-version":[{"id":364,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/posts\/363\/revisions\/364"}],"wp:attachment":[{"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/media?parent=363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/categories?post=363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/tags?post=363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}