{"id":366,"date":"2013-08-04T01:26:58","date_gmt":"2013-08-04T05:26:58","guid":{"rendered":"http:\/\/www.ferociouscoder.com\/blog\/?p=366"},"modified":"2016-11-28T12:03:16","modified_gmt":"2016-11-28T17:03:16","slug":"uva-10189-minesweeper","status":"publish","type":"post","link":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-10189-minesweeper-366.html","title":{"rendered":"UVA 10189 &#8211; Minesweeper"},"content":{"rendered":"<p>This is a problem that I solved earlier for the Programming Challenges book. Pretty simple problem.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\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 P10189 {\r\n\r\n  private static int&#x5B;] arr = { -1, 0, 1 };\r\n\r\n  public static void main(String&#x5B;] args) {\r\n    Scanner sc = new Scanner(System.in);\r\n    int count = 1;\r\n    while (sc.hasNextInt()) {\r\n      int y = sc.nextInt();\r\n      int x = sc.nextInt();\r\n      if (x == 0 &amp;&amp; y == 0)\r\n        break;\r\n      if (count != 1)\r\n        System.out.println();\r\n      char&#x5B;]&#x5B;] field = new char&#x5B;y + 2]&#x5B;x + 2];\r\n      for (int i = 0; i &lt; y; i++) {\r\n        String t = sc.next();\r\n        for (int j = 0; j &lt; x; j++)\r\n          field&#x5B;i + 1]&#x5B;j + 1] = t.charAt(j);\r\n      }\r\n\r\n      for (int i = 0; i &lt; y; i++) {\r\n        for (int j = 0; j &lt; x; j++) {\r\n          int mines = 0;\r\n          if (field&#x5B;i + 1]&#x5B;j + 1] == '*')\r\n            continue;\r\n          if (field&#x5B;i + 1]&#x5B;j + 1] == '.') {\r\n            for (int zz = 0; zz &lt; arr.length; zz++)\r\n              for (int yy = 0; yy &lt; arr.length; yy++)\r\n                if (zz == 1 &amp;&amp; yy == 1)\r\n                  continue;\r\n                else if (field&#x5B;i + 1 + arr&#x5B;zz]]&#x5B;j + 1 + arr&#x5B;yy]] == '*')\r\n                  mines++;\r\n\r\n            String zxc = &quot;&quot; + mines;\r\n            field&#x5B;i + 1]&#x5B;j + 1] = (zxc.charAt(0));\r\n          }\r\n\r\n        }\r\n      }\r\n\r\n      System.out.println(&quot;Field #&quot; + count + &quot;:&quot;);\r\n      for (int i = 0; i &lt; y; i++) {\r\n        for (int j = 0; j &lt; x; j++) {\r\n          if (j != x - 1)\r\n            System.out.print(field&#x5B;i + 1]&#x5B;j + 1]);\r\n          else\r\n            System.out.println(field&#x5B;i + 1]&#x5B;j + 1]);\r\n        }\r\n      }\r\n      count++;\r\n    }\r\n    sc.close();\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is a problem that I solved earlier for the Programming Challenges book. Pretty simple problem. import java.util.Scanner; \/** * * @author Sanchit M. Bhatnagar * @see http:\/\/uhunt.felix-halim.net\/id\/74004 * *\/ public class P10189 { private static int&#x5B;] arr = { -1, 0, 1 }; public static void main(String&#x5B;] args) { Scanner sc = new Scanner(System.in); &hellip; <a href=\"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-10189-minesweeper-366.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">UVA 10189 &#8211; Minesweeper<\/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":true,"_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,27,22],"class_list":["post-366","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-programming-challenges-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 10189 - Minesweeper - 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-10189-minesweeper-366.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"UVA 10189 - Minesweeper - Ferocious Coder\" \/>\n<meta property=\"og:description\" content=\"This is a problem that I solved earlier for the Programming Challenges book. Pretty simple problem. import java.util.Scanner; \/** * * @author Sanchit M. Bhatnagar * @see http:\/\/uhunt.felix-halim.net\/id\/74004 * *\/ public class P10189 { private static int&#x5B;] arr = { -1, 0, 1 }; public static void main(String&#x5B;] args) { Scanner sc = new Scanner(System.in); &hellip; Continue reading UVA 10189 &#8211; Minesweeper &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-10189-minesweeper-366.html\" \/>\n<meta property=\"og:site_name\" content=\"Ferocious Coder\" \/>\n<meta property=\"article:published_time\" content=\"2013-08-04T05:26:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-11-28T17:03:16+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-10189-minesweeper-366.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-10189-minesweeper-366.html\"},\"author\":{\"name\":\"Rawrosaur\",\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#\\\/schema\\\/person\\\/1fb5cbee546cffd619a7b301e3dc447a\"},\"headline\":\"UVA 10189 &#8211; Minesweeper\",\"datePublished\":\"2013-08-04T05:26:58+00:00\",\"dateModified\":\"2016-11-28T17:03:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-10189-minesweeper-366.html\"},\"wordCount\":219,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#\\\/schema\\\/person\\\/1fb5cbee546cffd619a7b301e3dc447a\"},\"keywords\":[\"competitive programming 3\",\"java\",\"programming challenges\",\"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-10189-minesweeper-366.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-10189-minesweeper-366.html\",\"url\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-10189-minesweeper-366.html\",\"name\":\"UVA 10189 - Minesweeper - Ferocious Coder\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#website\"},\"datePublished\":\"2013-08-04T05:26:58+00:00\",\"dateModified\":\"2016-11-28T17:03:16+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-10189-minesweeper-366.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-10189-minesweeper-366.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-10189-minesweeper-366.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"UVA 10189 &#8211; Minesweeper\"}]},{\"@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 10189 - Minesweeper - 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-10189-minesweeper-366.html","og_locale":"en_US","og_type":"article","og_title":"UVA 10189 - Minesweeper - Ferocious Coder","og_description":"This is a problem that I solved earlier for the Programming Challenges book. Pretty simple problem. import java.util.Scanner; \/** * * @author Sanchit M. Bhatnagar * @see http:\/\/uhunt.felix-halim.net\/id\/74004 * *\/ public class P10189 { private static int&#x5B;] arr = { -1, 0, 1 }; public static void main(String&#x5B;] args) { Scanner sc = new Scanner(System.in); &hellip; Continue reading UVA 10189 &#8211; Minesweeper &rarr;","og_url":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-10189-minesweeper-366.html","og_site_name":"Ferocious Coder","article_published_time":"2013-08-04T05:26:58+00:00","article_modified_time":"2016-11-28T17:03:16+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-10189-minesweeper-366.html#article","isPartOf":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-10189-minesweeper-366.html"},"author":{"name":"Rawrosaur","@id":"https:\/\/www.ferociouscoder.com\/blog\/#\/schema\/person\/1fb5cbee546cffd619a7b301e3dc447a"},"headline":"UVA 10189 &#8211; Minesweeper","datePublished":"2013-08-04T05:26:58+00:00","dateModified":"2016-11-28T17:03:16+00:00","mainEntityOfPage":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-10189-minesweeper-366.html"},"wordCount":219,"commentCount":0,"publisher":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/#\/schema\/person\/1fb5cbee546cffd619a7b301e3dc447a"},"keywords":["competitive programming 3","java","programming challenges","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-10189-minesweeper-366.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-10189-minesweeper-366.html","url":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-10189-minesweeper-366.html","name":"UVA 10189 - Minesweeper - Ferocious Coder","isPartOf":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/#website"},"datePublished":"2013-08-04T05:26:58+00:00","dateModified":"2016-11-28T17:03:16+00:00","breadcrumb":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-10189-minesweeper-366.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-10189-minesweeper-366.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-10189-minesweeper-366.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.ferociouscoder.com\/blog"},{"@type":"ListItem","position":2,"name":"UVA 10189 &#8211; Minesweeper"}]},{"@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-5U","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/posts\/366","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=366"}],"version-history":[{"count":1,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/posts\/366\/revisions"}],"predecessor-version":[{"id":367,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/posts\/366\/revisions\/367"}],"wp:attachment":[{"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/media?parent=366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/categories?post=366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/tags?post=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}