{"id":1261,"date":"2022-06-03T19:01:02","date_gmt":"2022-06-03T11:01:02","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=1261"},"modified":"2022-06-03T19:01:02","modified_gmt":"2022-06-03T11:01:02","slug":"hj94-%e8%ae%b0%e7%a5%a8%e7%bb%9f%e8%ae%a1","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2022\/06\/03\/hj94-%e8%ae%b0%e7%a5%a8%e7%bb%9f%e8%ae%a1\/","title":{"rendered":"HJ94 \u8bb0\u7968\u7edf\u8ba1"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u63cf\u8ff0<\/h2>\n\n\n\n<p>\u8bf7\u5b9e\u73b0\u4e00\u4e2a\u8ba1\u7968\u7edf\u8ba1\u7cfb\u7edf\u3002\u4f60\u4f1a\u6536\u5230\u5f88\u591a\u6295\u7968\uff0c\u5176\u4e2d\u6709\u5408\u6cd5\u7684\u4e5f\u6709\u4e0d\u5408\u6cd5\u7684\uff0c\u8bf7\u7edf\u8ba1\u6bcf\u4e2a\u5019\u9009\u4eba\u5f97\u7968\u7684\u6570\u91cf\u4ee5\u53ca\u4e0d\u5408\u6cd5\u7684\u7968\u6570\u3002\uff08\u6ce8\uff1a\u4e0d\u5408\u6cd5\u7684\u6295\u7968\u6307\u7684\u662f\u6295\u7968\u7684\u540d\u5b57\u4e0d\u5b58\u5728n\u4e2a\u5019\u9009\u4eba\u7684\u540d\u5b57\u4e2d\uff01\uff01\uff09<br>\u6570\u636e\u8303\u56f4\uff1a\u6bcf\u7ec4\u8f93\u5165\u4e2d\u5019\u9009\u4eba\u6570\u91cf\u6ee1\u8db3\u00a01\u2264<em>n<\/em>\u2264100\u00a0\u00a0\uff0c\u603b\u7968\u6570\u91cf\u6ee1\u8db3\u00a01\u2264<em>n<\/em>\u2264100\u00a0<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8f93\u5165\u63cf\u8ff0\uff1a<\/h3>\n\n\n\n<p>\u7b2c\u4e00\u884c\u8f93\u5165\u5019\u9009\u4eba\u7684\u4eba\u6570n\uff0c\u7b2c\u4e8c\u884c\u8f93\u5165n\u4e2a\u5019\u9009\u4eba\u7684\u540d\u5b57\uff08\u5747\u4e3a\u5927\u5199\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32\uff09\uff0c\u7b2c\u4e09\u884c\u8f93\u5165\u6295\u7968\u4eba\u7684\u4eba\u6570\uff0c\u7b2c\u56db\u884c\u8f93\u5165\u6295\u7968\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8f93\u51fa\u63cf\u8ff0\uff1a<\/h3>\n\n\n\n<p>\u6309\u7167\u8f93\u5165\u7684\u987a\u5e8f\uff0c\u6bcf\u884c\u8f93\u51fa\u5019\u9009\u4eba\u7684\u540d\u5b57\u548c\u5f97\u7968\u6570\u91cf\uff08\u4ee5&#8221; : &#8220;\u9694\u5f00\uff0c\u6ce8\uff1a\u82f1\u6587\u5192\u53f7\u5de6\u53f3\u4e24\u8fb9\u90fd\u6709\u4e00\u4e2a\u7a7a\u683c\uff01\uff09\uff0c\u6700\u540e\u4e00\u884c\u8f93\u51fa\u4e0d\u5408\u6cd5\u7684\u7968\u6570\uff0c\u683c\u5f0f\u4e3a&#8221;Invalid : &#8220;+\u4e0d\u5408\u6cd5\u7684\u7968\u6570\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b1<\/h2>\n\n\n\n<p>\u8f93\u5165\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">4\nA B C D\n8\nA D E CF A GG A B<\/pre>\n\n\n\n<p>\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">A : 3\nB : 1\nC : 0\nD : 1\nInvalid : 3<\/pre>\n\n\n\n<p>\u8bf4\u660e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">E CF GG\u4e09\u5f20\u7968\u662f\u65e0\u6548\u7684\uff0c\u6240\u4ee5Invalid\u7684\u6570\u91cf\u662f3.<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.*;\n\npublic class Main{\n    public static void main(String&#91;] args){\n        Scanner in = new Scanner(System.in);\n        while(in.hasNext()){\n            int n = in.nextInt();\n            in.nextLine();                    \/\/\u7528\u4e8e\u8fc7\u6ee4nextInt()\u65b9\u6cd5\u540e\u9762\u7684Enter\u7b49\u7ed3\u675f\u7b26\n            String can = in.nextLine();\n            int m = in.nextInt();\n            in.nextLine();                    \/\/\u7528\u4e8e\u8fc7\u6ee4nextInt()\u65b9\u6cd5\u540e\u9762\u7684Enter\u7b49\u7ed3\u675f\u7b26\n            String votes = in.nextLine();\n            int valid = 0;\n            for(String name: can.split(\" \")){\n                int times = 0;\n                for(String vote: votes.split(\" \")){\n                    if(name.equals(vote)){\n                        times++;\n                    }\n                }\n                System.out.println(name + \" : \" + times);\n                valid += times;\n            }\n            int invalid = m - valid;\n            System.out.println(\"Invalid : \" + invalid);\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>nextInt()\u65b9\u6cd5\u540e\u8fb9\u4e0d\u80fd\u7d27\u8ddf\u7740nextLine()\u65b9\u6cd5\uff0c\u4e0d\u7136\u4f1a\u62a5\u9519\uff0c\u8fd9\u662f\u56e0\u4e3anextInt()\u65b9\u6cd5\u4f1a\u628a\u6570\u5b57\u540e\u7684Enter\u952e\u6216\u7a7a\u683c\u952e\u89c6\u4e3a\u7ed3\u675f\u7b26\u6216\u5206\u9694\u7b26\uff0c\u5176\u4ecd\u5728\u7f13\u51b2\u533a\u5185\uff0c\u5982\u679c\u7d27\u63a5\u7740\u7528nextLine()\u65b9\u6cd5\uff0c\u5c31\u4f1a\u8bfb\u5165\u8fd9\u4e2a\u7ed3\u675f\u7b26\uff0c\u5bfc\u81f4\u65e0\u6cd5\u8f93\u5165\u3002<\/li><\/ol>\n\n\n\n<p>\u3000\u3000\u89e3\u51b3\u529e\u6cd5\uff1a 1. \u5728nextInt()\u548cnextLine()\u4e4b\u95f4\u518d\u52a0\u4e00\u884cnextLine()\u7528\u4ee5\u7f13\u51b2\uff1b 2. \u9009\u7528next()\u65b9\u6cd5\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u6bd4\u8f83\u65f6\uff0c\u201c==\u201d\u8fd0\u7b97\u7b26\u6307\u5224\u65ad\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u6307\u5411\u540c\u4e00\u5bf9\u8c61\uff0c\u800c\u8981\u5224\u65ad\u4e24\u4e2a\u5b57\u7b26\u4e32\u5185\u5bb9\u662f\u5426\u76f8\u7b49\uff0c\u5219\u8981\u7528equals()\u65b9\u6cd5\uff1astr1.equals(str2);<\/li><\/ol>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63cf\u8ff0 \u8bf7\u5b9e\u73b0\u4e00\u4e2a\u8ba1\u7968\u7edf\u8ba1\u7cfb\u7edf\u3002\u4f60&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1257,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1261","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=1261"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1261\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media\/1257"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=1261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=1261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=1261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}