{"id":322,"date":"2024-04-27T23:01:58","date_gmt":"2024-04-27T15:01:58","guid":{"rendered":"https:\/\/seanxd.com\/?p=322"},"modified":"2024-04-27T23:02:00","modified_gmt":"2024-04-27T15:02:00","slug":"zerojudge-c012","status":"publish","type":"post","link":"https:\/\/seanxd.com\/zh\/zerojudge-c012\/","title":{"rendered":"ZeroJudge C012: Tell me the frequencies!"},"content":{"rendered":"\n\n\n<p class=\"\">\u7d66\u4f60\u4e00\u5217\u6587\u5b57\uff0c\u8acb\u4f60\u627e\u51fa\u5404\u5b57\u5143\u51fa\u73fe\u7684\u6b21\u6578\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"wp-block-table nfd-wb-animate nfd-wb-fade-in-bottom-short\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td><strong>EOF<\/strong> \u8f38\u5165\uff0c\u6bcf\u7b46\u6e2c\u8a66\u8cc7\u6599\u4e00\u5217\u3002\u6bcf\u5217\u6700\u5927\u9577\u5ea6\u70ba1000\u3002<\/td><td>\u5c0d\u6bcf\u4e00\u5217\u8f38\u5165\uff0c\u8acb<strong>\u8f38\u51fa\u5404\u5b57\u5143\u7684 ASCII \u503c\u53ca\u5176\u51fa\u73fe\u7684\u6b21\u6578<\/strong>\u3002\u8acb\u6839\u64da\u51fa\u73fe\u7684\u6b21\u6578\u7531\u5c0f\u5230\u5927\u8f38\u51fa\u3002\u5982\u679c\u6709 <strong>2 \u500b\u4ee5\u4e0a\u7684\u5b57\u5143\u6709\u76f8\u540c\u7684\u6b21\u6578\uff0c\u5247 ASCII \u503c\u8f03\u5927\u7684\u5148\u8f38\u51fa<\/strong>\u3002\u6e2c\u8a66\u8cc7\u6599\u9593\u8acb\u7a7a\u4e00\u5217<\/td><\/tr><tr><td>AAABBC<br>122333<\/td><td>67  1<br>66  2<br>65  3<br><br>49  1<br>50  2<br>51  3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p class=\"\">\u56e0\u70ba<strong>\u6703\u6709\u7a7a\u683c\u6240\u4ee5\u8981\u7528 Getline \u4f86\u505a\u8f38\u5165<\/strong>\uff0c\u53ef\u4ee5<strong>\u4f7f\u7528 Map \u4f86\u7d00\u9304\u6bcf\u4e00\u500b\u5b57\u5143\u51fa\u73fe\u7684\u6b21\u6578<\/strong>\u3002<\/p>\n\n\n\n<p class=\"\">\u505a\u5b8c\u6b21\u6578\u7684\u5224\u65b7\u4e4b\u5f8c<strong>\u4f7f\u7528 Auto \u8dd1 Map \u7684 For\u8ff4\u5708<\/strong>\uff0c\u4e26\u4e14<strong>\u518d\u5efa\u7acb\u4e00\u500b\u5b58\u7b54\u6848\u7684 Map<\/strong>\uff0c<strong>Key \u662f\u51fa\u73fe\u7684\u6b21\u6578\uff0c\u503c\u662f\u4e00\u500b Vector \u7528\u4f86\u5b58\u591a\u500b\u5b57\u5143\u4e26\u4e14\u505a\u6392\u5e8f<\/strong>\u3002<\/p>\n\n\n\n<p class=\"\">\u6bcf\u6b21\u5c07\u7b54\u6848 Map \u7684 Vector \u9032\u884c Assign \u5230\u4e00\u500b\u66ab\u5b58Vector\u4e0a\u4e26\u4e14\u5c07\u76ee\u524d\u7684\u5b57\u5143\u505a Push_Back \u5230\u9019\u500b\u66ab\u5b58\u7684Vector\u4e2d\uff0c\u7136\u5f8c\u9032\u884cSort\u7684\u6392\u5e8f\uff0c\u6700\u5f8c\u5c07\u66ab\u5b58\u7684Vector\u91cd\u65b0Assign\u56de\u7b54\u6848Map\u4e2d\u7684\u503c\u3002<\/p>\n\n\n\n<p class=\"\">\u6700\u5f8c\u4e00\u6a23\u7528 <strong>Auto \u8dd1\u7b54\u6848 Map \u7684 For\u8ff4\u5708<\/strong>\uff0c\u88e1\u9762\u518d\u8dd1 Map \u503c\u4e2d\u7684 Vector \u7684For\u8ff4\u5708\uff0c\u8f38\u51fa\u5b57\u5143\u7684 Ascii Code \u5373\u53ef\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=c012\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge C012: Tell me the frequencies!<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right nfd-delay-50\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\n#include &lt;map&gt;\n#include &lt;algorithm&gt;\n#include &lt;vector&gt;\nusing namespace std;\n\nint main() {\n    string str;\n    while (getline(cin, str))\n    {\n        map&lt;int, int&gt;MAP;\n        for (int i = 0; i&lt;str.length(); i++)\n        {\n            MAP[float(str[i])]++;\n        }\n        map&lt;int, vector&lt;int&gt;&gt;ans;\n        for (auto it:MAP)\n        {\n            vector&lt;int&gt;tmp;\n            tmp.assign(ans[it.second].begin(), ans[it.second].end());\n            tmp.push_back(it.first);\n            sort(tmp.begin(), tmp.end());\n            reverse(tmp.begin(), tmp.end());\n            ans[it.second].assign(tmp.begin(), tmp.end());\n        }\n        for (auto it:ans)\n        {\n            vector&lt;int&gt;tmp = it.second;\n            for (int i = 0; i&lt;tmp.size(); i++)\n            {\n                cout &lt;&lt; tmp[i] &lt;&lt; &quot; &quot; &lt;&lt; it.first &lt;&lt; &quot;\\n&quot;;\n            }\n            cout &lt;&lt; &quot;\\n&quot;;\n        }\n    }\n}\n\n\/\/ZeroJudge C012\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7d66\u4f60\u4e00\u5217\u6587\u5b57\uff0c\u8acb\u4f60\u627e\u51fa\u5404\u5b57\u5143\u51fa\u73fe\u7684\u6b21\u6578\u3002 \u7bc4\u4f8b\u6e2c\u8cc7 \u7bc4\u4f8b\u8f38\u5165 \u7bc4\u4f8b\u8f38\u51fa EOF \u8f38\u5165\uff0c\u6bcf\u7b46\u6e2c\u8a66\u8cc7\u6599\u4e00\u5217\u3002\u6bcf\u5217\u6700 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[18],"tags":[14,23,20,11,19,9],"class_list":["post-322","post","type-post","status-publish","format-standard","hentry","category-uva","tag-map","tag-pair","tag-20","tag-11","tag-19","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/comments?post=322"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/322\/revisions"}],"predecessor-version":[{"id":323,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/posts\/322\/revisions\/323"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/media?parent=322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/categories?post=322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/zh\/wp-json\/wp\/v2\/tags?post=322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}