{"id":1116,"date":"2022-05-17T20:44:47","date_gmt":"2022-05-17T12:44:47","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=1116"},"modified":"2022-05-17T20:44:47","modified_gmt":"2022-05-17T12:44:47","slug":"%e5%8d%8e%e4%b8%ba%e6%9c%ba%e8%af%95hj8%e5%90%88%e5%b9%b6%e8%a1%a8%e8%ae%b0%e5%bd%95","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2022\/05\/17\/%e5%8d%8e%e4%b8%ba%e6%9c%ba%e8%af%95hj8%e5%90%88%e5%b9%b6%e8%a1%a8%e8%ae%b0%e5%bd%95\/","title":{"rendered":"\u534e\u4e3a\u673a\u8bd5HJ8\u5408\u5e76\u8868\u8bb0\u5f55\uff08hashmap\u53bb\u91cd\uff09"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package HuaWei;\n\/*\nAuthor:Sanro\nTime:2022.05.15 14:01:01\nBlog:https:\/\/sanlangcode.com\nEmail:sanlangcode@163.com\nDesc:\n\u63cf\u8ff0\n\u6570\u636e\u8868\u8bb0\u5f55\u5305\u542b\u8868\u7d22\u5f15index\u548c\u6570\u503cvalue\uff08int\u8303\u56f4\u7684\u6b63\u6574\u6570\uff09\uff0c\u8bf7\u5bf9\u8868\u7d22\u5f15\u76f8\u540c\u7684\u8bb0\u5f55\u8fdb\u884c\u5408\u5e76\uff0c\u5373\u5c06\u76f8\u540c\u7d22\u5f15\u7684\u6570\u503c\u8fdb\u884c\u6c42\u548c\u8fd0\u7b97\uff0c\u8f93\u51fa\u6309\u7167index\u503c\u5347\u5e8f\u8fdb\u884c\u8f93\u51fa\u3002\n\n\n\u63d0\u793a:\n0 &lt;= index &lt;= 11111111\n1 &lt;= value &lt;= 100000\n\n\u8f93\u5165\u63cf\u8ff0\uff1a\n\u5148\u8f93\u5165\u952e\u503c\u5bf9\u7684\u4e2a\u6570n\uff081 &lt;= n &lt;= 500\uff09\n\u63a5\u4e0b\u6765n\u884c\u6bcf\u884c\u8f93\u5165\u6210\u5bf9\u7684index\u548cvalue\u503c\uff0c\u4ee5\u7a7a\u683c\u9694\u5f00\n\n\u8f93\u51fa\u63cf\u8ff0\uff1a\n\u8f93\u51fa\u5408\u5e76\u540e\u7684\u952e\u503c\u5bf9\uff08\u591a\u884c\uff09\n\n\u793a\u4f8b1\n\u8f93\u5165\uff1a\n4\n0 1\n0 2\n1 2\n3 4\n\u590d\u5236\n\u8f93\u51fa\uff1a\n0 3\n1 2\n3 4\n\u590d\u5236\n\u793a\u4f8b2\n\u8f93\u5165\uff1a\n3\n0 1\n0 2\n8 9\n\u590d\u5236\n\u8f93\u51fa\uff1a\n0 3\n8 9\n\n*\/\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Scanner;\n\/\/\u6570\u636e\u8868\u8bb0\u5f55\u5305\u542b\u8868\u7d22\u5f15index\u548c\u6570\u503cvalue\uff08int\u8303\u56f4\u7684\u6b63\u6574\u6570\uff09\uff0c\n\/\/ \u8bf7\u5bf9\u8868\u7d22\u5f15\u76f8\u540c\u7684\u8bb0\u5f55\u8fdb\u884c\u5408\u5e76\uff0c\n\/\/ \u5373\u5c06\u76f8\u540c\u7d22\u5f15\u7684\u6570\u503c\u8fdb\u884c\u6c42\u548c\u8fd0\u7b97\uff0c\u8f93\u51fa\u6309\u7167index\u503c\u5347\u5e8f\u8fdb\u884c\u8f93\u51fa\u3002\n\/\/        \u63d0\u793a:\n\/\/        0 &lt;= index &lt;= 11111111\n\/\/        1 &lt;= value &lt;= 100000\n\/\/\n\/\/        \u8f93\u5165\u63cf\u8ff0\uff1a\n\/\/        \u5148\u8f93\u5165\u952e\u503c\u5bf9\u7684\u4e2a\u6570n\uff081 &lt;= n &lt;= 500\uff09\n\/\/        \u63a5\u4e0b\u6765n\u884c\u6bcf\u884c\u8f93\u5165\u6210\u5bf9\u7684index\u548cvalue\u503c\uff0c\u4ee5\u7a7a\u683c\u9694\u5f00\n\/\/\n\/\/        \u8f93\u51fa\u63cf\u8ff0\uff1a\n\/\/        \u8f93\u51fa\u5408\u5e76\u540e\u7684\u952e\u503c\u5bf9\uff08\u591a\u884c\uff09\n\/\/\u8f93\u5165\uff1a\n\/\/4\n\/\/0 1\n\/\/0 2\n\/\/1 2\n\/\/3 4\n\/\/\n\/\/\u8f93\u51fa\uff1a\n\/\/0 3\n\/\/1 2\n\/\/3 4\npublic class HJ8\u5408\u5e76\u8868\u8bb0\u5f55HashMap {\n    \/\/\u54c8\u5e0c\u8868\u91cd\u4e2d\u4e4b\u91cd\n    public static void main(String&#91;] args) {\n        Scanner scanner = new Scanner(System.in);\n        int tableSize = scanner.nextInt();\n        Map&lt;Integer, Integer> table = new HashMap&lt;>(tableSize);\n        for (int i = 0; i &lt; tableSize; i++) {\n            int key = scanner.nextInt();\n            int value = scanner.nextInt();\n            if (table.containsKey(key)) {\n                table.put(key, table.get(key) + value);\n            } else {\n                table.put(key, value);\n            }\n        }\n        for (Integer key : table.keySet()) {\n            System.out.println( key + \" \" + table.get(key));\n        }\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":1114,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-1116","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-25"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=1116"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1116\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media\/1114"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=1116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=1116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=1116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}