{"id":342,"date":"2024-04-28T11:00:47","date_gmt":"2024-04-28T03:00:47","guid":{"rendered":"https:\/\/seanxd.com\/?p=342"},"modified":"2024-04-28T11:00:49","modified_gmt":"2024-04-28T03:00:49","slug":"zerojudge-n327","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-n327\/","title":{"rendered":"ZeroJudge N327: The Tower of Names"},"content":{"rendered":"\n\n\n<p class=\"\">\u5728\u82f1\u6587\u88e1\uff0c\u5f88\u591a\u540d\u5b57\u51fa\u73fe\u5728\u4e00\u500b\u6e05\u55ae\u6642\uff0c\u5e38\u5e38\u6703\u4ee5\u82f1\u6587\u5b57\u6bcd\u6392\u5e8f (Alphabetical Order)\uff0c\u65b9\u4fbf\u4eba\u5011\u67e5\u627e\u3002\u4f46\u662f\u6587\u6587\u89ba\u5f97\u9019\u6a23\u9577\u77ed\u4e0d\u4e00\u7684\u540d\u5b57\u6df7\u96dc\u5728\u4e00\u8d77\uff0c\u4e0d\u592a\u6574\u9f4a\uff0c\u65bc\u662f\u4ed6\u5c31<strong>\u5148\u7528\u540d\u5b57\u7684\u9577\u77ed\u6392\u5e8f\uff0c\u76f8\u540c\u9577\u5ea6\u7684\u540d\u5b57\u624d\u4ee5\u5b57\u6bcd\u6392\u5e8f<\/strong>\uff0c\u5982\u6b64\u4e00\u4f86\uff0c\u7576\u4f60\u628a\u9019\u540d\u5b57\u7684\u6e05\u55ae\u5217\u51fa\u4f86\u662f\u6703\u662f<strong>\u4e0a\u7a84\u4e0b\u5bec<\/strong>\uff0c\u770b\u8d77\u4f86\u5c31\u50cf\u662f\u4e00\u5ea7\u5854\u3002<\/p>\n\n\n\n<p class=\"\">\u7d66\u4f60\u82e5\u5e72\u500b\u540d\u5b57\uff0c\u8acb\u4ee5\u6587\u6587\u7684\u65b9\u5f0f\u6392\u5e8f\u5f8c\u8f38\u51fa\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>\u8f38\u5165\u7684\u7b2c\u4e00\u884c\u542b\u6709\u4e00\u500b\u6574\u6578 N (0 &lt; N &lt;= 100)\uff0c\u63a5\u4e0b\u4f86\u6709 N \u884c\uff0c\u6bcf\u884c\u542b\u6709\u4e00\u500b<strong>\u7531\u82f1\u6587\u5b57\u6bcd\u3001\u53e5\u9ede (.)\u3001\u9023\u5b57\u865f (-)\u3001\u96d9\u5f15\u865f (&#8220;)\u3001\u53ca\u300c\u7a7a\u767d<\/strong>\u300d\u6240\u7d44\u6210\u7684\u82f1\u6587\u59d3\u540d\u3002<\/td><td>\u5c07\u8f38\u5165\u7684\u59d3\u540d\u5148\u4ee5\u9577\u5ea6 <strong>(\u542b\u4e2d\u9593\u7684\u7a7a\u767d\u53ca\u5176\u5b83\u7b26\u865f)<\/strong> \u6392\u5e8f\uff0c\u9577\u5ea6\u76f8\u540c\u6642\uff0c\u5247\u4ee5\u5b57\u6bcd\u9806\u5e8f\u6392\u5e8f\u3002<\/td><\/tr><tr><td>5<br>Alexander Smith<br>Mia Johnson<br>Benjamin Lee<br>Isabella Chang<br>Oliver Taylor<\/td><td>Mia Johnson<br>Benjamin Lee<br>Oliver Taylor<br>Isabella Chang<br>Alexander Smith<\/td><\/tr><tr><td>4<br>Ethan Baker<br>April Adams<br>Jacob White<br>Emily Clark<\/td><td>April Adams<br>Emily Clark<br>Ethan Baker<br>Jacob White<\/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=\"\">\u5c07 N \u9032\u884c\u8f38\u5165\u5f8c\u8981<strong>\u5148\u9032\u884c\u4e00\u6b21\u7121\u7528\u7684 getline\uff0c\u9019\u6a23\u4e4b\u5f8c\u7684 getline \u624d\u6703\u90fd\u6536\u5f97\u5230\u8cc7\u6599<\/strong>\u3002<\/p>\n\n\n\n<p class=\"\">\u5ba3\u544a\u4e00\u500b <strong>Map&lt;int, vector&lt;string>><\/strong>\uff0cKey \u503c\u70ba\u5b57\u4e32\u7684\u9577\u5ea6\uff0c Value \u503c\u70ba\u9019\u500b\u9577\u5ea6\u6709\u54ea\u4e9b\u5b57\u4e32\u3002\u6536\u5b57\u4e32\u7684\u6642\u5019\u5224\u65b7\u9019\u500b\u5b57\u4e32\u7684\u9577\u5ea6\uff0c\u4e26\u5c07\u9019\u500b\u5b57\u4e32 Push_Back \u5230 Map[\u5b57\u4e32\u9577\u5ea6] \u4e2d\u3002<\/p>\n\n\n\n<p class=\"\">\u8f38\u51fa\u6642\u4f7f\u7528 <strong>for (auto it:Map)<\/strong>\uff0c\u5c07<strong> it.second \u9032\u884c Sort <\/strong>\u4e4b\u5f8c\u518d\u958b\u4e00\u500b<strong> For\u8ff4\u5708 <\/strong>\u5c07 it.second (Vector&lt;string>) \u4e2d\u7684\u8cc7\u6599\u4f9d\u5e8f\u8f38\u51fa\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=n327\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge N327: The Tower of Names<\/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;vector&gt;\n#include &lt;map&gt;\n#include &lt;algorithm&gt;\nusing namespace std;\n\nint main() {\n    int N;\n    cin &gt;&gt; N;\n    string s;\n    getline(cin, s);\n    map&lt;int, vector&lt;string&gt;&gt;MAP;\n    for (int i = 0; i&lt;N; i++)\n    {\n        string str;\n        getline(cin, str);\n        vector&lt;string&gt;tmp;\n        int len = int(str.length());\n        tmp.assign(MAP[len].begin(), MAP[len].end());\n        tmp.push_back(str);\n        sort(tmp.begin(), tmp.end());\n        MAP[len].clear();\n        MAP[len].assign(tmp.begin(), tmp.end());\n    }\n    for (auto it:MAP)\n    {\n        vector&lt;string&gt;tmp = it.second;\n        for (int i = 0; i&lt;tmp.size(); i++)\n        {\n            cout &lt;&lt; tmp[i] &lt;&lt; &quot;\\n&quot;;\n        }\n    }\n}\n\n\/\/ZeroJudge N327\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u82f1\u6587\u88e1\uff0c\u5f88\u591a\u540d\u5b57\u51fa\u73fe\u5728\u4e00\u500b\u6e05\u55ae\u6642\uff0c\u5e38\u5e38\u6703\u4ee5\u82f1\u6587\u5b57\u6bcd\u6392\u5e8f (Alphabetical Order)\uff0c\u65b9\u4fbf\u4eba\u5011\u67e5 [&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":[6],"tags":[14,23,20,11,19,9],"class_list":["post-342","post","type-post","status-publish","format-standard","hentry","category-6","tag-map","tag-pair","tag-20","tag-11","tag-19","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=342"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/342\/revisions"}],"predecessor-version":[{"id":343,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/342\/revisions\/343"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}