{"id":158,"date":"2012-05-29T12:13:01","date_gmt":"2012-05-29T04:13:01","guid":{"rendered":"http:\/\/wangkaixuan.tech\/?p=158"},"modified":"2020-06-04T12:13:43","modified_gmt":"2020-06-04T04:13:43","slug":"poj-1002-java","status":"publish","type":"post","link":"http:\/\/www.wangkaixuan.tech\/?p=158","title":{"rendered":"poj 1002 Java"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>import java.io.BufferedReader;\nimport java.io.InputStreamReader;\nimport java.util.HashMap;\nimport java.util.Iterator;\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.TreeSet;\n \npublic class Main {\n\tstatic public char returnValue(char c) {\n\t\tif (c &lt;= 67 &amp;&amp; c >= 65) {\n\t\t\treturn '2';\n\t\t} else if (c &lt;= 70 &amp;&amp; c >= 68) {\n\t\t\treturn '3';\n\t\t} else if (c &lt;= 73 &amp;&amp; c >= 71) {\n\t\t\treturn '4';\n\t\t} else if (c &lt;= 76 &amp;&amp; c >= 74) {\n\t\t\treturn '5';\n\t\t} else if (c &lt;= 79 &amp;&amp; c >= 77) {\n\t\t\treturn '6';\n\t\t} else if (c &lt;= 83 &amp;&amp; c >= 80) {\n\t\t\treturn '7';\n\t\t} else if (c &lt;= 86 &amp;&amp; c >= 84) {\n\t\t\treturn '8';\n\t\t} else if (c &lt;= 89 &amp;&amp; c >= 87) {\n\t\t\treturn '9';\n\t\t} else {\n\t\t\treturn '0';\n\t\t}\n\t}\n \n\tpublic static String parse(String str) {\n\t\tString temp = \"\";\n\t\tfor (int j = 0; j &lt; str.length(); j++) {\n\t\t\tif (str.charAt(j) == '-') {\n\t\t\t\tcontinue;\n\t\t\t} else {\n\t\t\t\tchar t = str.charAt(j);\n\t\t\t\tif (t >= '0' &amp;&amp; t &lt;= '9') {\n\t\t\t\t\ttemp += t;\n\t\t\t\t} else {\n\t\t\t\t\ttemp += returnValue(t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn temp;\n\t}\n \n\tpublic static void main(String&#91;] args) throws Exception {\n\t\tBufferedReader in = new BufferedReader(new InputStreamReader(System.in));\n\t\tMap&lt;String, Integer> m = new HashMap&lt;String, Integer>();\n\t\tint ncase = Integer.parseInt(in.readLine());\n\t\twhile (ncase-- != 0) {\n\t\t\tString str = in.readLine();\n\t\t\t\/*\u6b64\u65b9\u6cd5\u592a\u8017\u65f6\uff0c\u4e0d\u53ef\u7528\n\t\t\t * str = str.replaceAll(\"-\", \"\").replaceAll(\"&#91;ABC]\", \"2\")\n\t\t\t * .replaceAll(\"&#91;DEF]\", \"3\").replaceAll(\"&#91;GHI]\", \"4\")\n\t\t\t * .replaceAll(\"&#91;JKL]\", \"5\").replaceAll(\"&#91;MNO]\", \"6\")\n\t\t\t * .replaceAll(\"&#91;PRS]\", \"7\").replaceAll(\"&#91;TUV]\", \"8\")\n\t\t\t * .replaceAll(\"&#91;WXY]\", \"9\");\n\t\t\t *\/\n\t\t\tstr = parse(str);\n\t\t\tInteger times = m.get(str);\n\t\t\tm.put(str, times == null ? 1 : times + 1);\n\t\t}\n\t\tSet&lt;String> keys = new TreeSet&lt;String>(m.keySet());\n\t\tboolean hasOutput = false;\n\t\tfor (Iterator&lt;String> it = keys.iterator(); it.hasNext();) {\n\t\t\tString key = it.next();\n\t\t\tif (m.get(key) > 1) {\n\t\t\t\thasOutput = true;\n\t\t\t\tSystem.out.println(key.substring(0, 3) + \"-\"\n\t\t\t\t\t\t+ key.substring(3, 7) + \" \" + m.get(key));\n\t\t\t}\n\t\t}\n\t\tif (!hasOutput) {\n\t\t\tSystem.out.println(\"No duplicates.\");\n\t\t}\n\t}\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-158","post","type-post","status-publish","format-standard","hentry","category-06-01-acm"],"_links":{"self":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=158"}],"version-history":[{"count":0,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}