{"id":1062,"date":"2024-08-10T09:00:00","date_gmt":"2024-08-10T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1062"},"modified":"2024-07-08T14:48:07","modified_gmt":"2024-07-08T06:48:07","slug":"zerojudge-e641","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-e641\/","title":{"rendered":"ZeroJudge E641: Soundex"},"content":{"rendered":"\n\n\n<h4 class=\"wp-block-heading\">\u540c\u984c\uff1aUVa 10260 &#8211; Soundex<\/h4>\n\n\n\n<p>Soundex \u7de8\u78bc\u6839\u64da\u62fc\u5beb\u5c07\u807d\u8d77\u4f86\u76f8\u4f3c\u7684\u55ae\u8a5e\u7d44\u5408\u5728\u4e00\u8d77\u3002<br>\u4f8b\u5982\uff1a\u300ccan\u300d\u548c\u300ckhawn\u300d\uff0c\u300ccon\u300d\u548c\u300cgone\u300d\u3002<br>Soundex \u7de8\u78bc\u5c07\u6bcf\u500b\u55ae\u8a5e\u8f49\u63db\u70ba\u4e00\u7d44\u6578\u5b57\uff0c\u5176\u4e2d\u6bcf\u500b\u6578\u5b57\u4ee3\u8868\u4e00\u500b\u5b57\u6bcd\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u70baSoundex\u7de8\u78bc\u8868\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>1\uff1aB\u3001F\u3001P\u3001V<\/li>\n\n\n\n<li>2\uff1aC\u3001G\u3001J\u3001K\u3001Q\u3001S\u3001X\u3001Z<\/li>\n\n\n\n<li>3\uff1aD\u3001T<\/li>\n\n\n\n<li>4\uff1aL<\/li>\n\n\n\n<li>5\uff1aM\u3001N<\/li>\n\n\n\n<li>6\uff1aR<\/li>\n<\/ul>\n\n\n\n<p>Soundex \u7de8\u78bc\u4e2d\u672a\u8868\u793a\u5b57\u6bcd\u300cA\u3001E\u3001I\u3001O\u3001U\u3001H\u3001W\u3001Y\u300d\u3002<br>\u5177\u6709\u76f8\u540c\u7de8\u78bc\u5b57\u6bcd\u5982\u679c\u76f8\u9130\u7684\u91cd\u8907\u51fa\u73fe\u50c5\u4ee5\u4e00\u500b\u6578\u5b57\u8868\u793a\u3002<br>\u5177\u6709\u76f8\u540c\u7de8\u78bc\u7684\u55ae\u8a5e\u8996\u70ba\u76f8\u540c\u55ae\u5b57\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\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td>EOF \u8f38\u5165\uff0c\u8f38\u5165\u7684\u6bcf\u4e00\u884c\u90fd\u5305\u542b\u4e00\u500b\u55ae\u8a5e\uff0c\u5168\u90e8\u70ba\u5927\u5beb\u5b57\u6bcd\u3002<br>\u55ae\u8a5e\u9577\u5ea6\u5c0f\u65bc 20 \u500b\u5b57\u6bcd\u3002<\/td><td>\u5c0d\u65bc\u6bcf\u884c\uff0c\u8f38\u51fa\u6b64\u55ae\u8a5e\u7684 Soundex Code\u3002<\/td><\/tr><tr><td>KHAWN<br>PFISTER<br>BOBBY<\/td><td>25<br>1236<br>11<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u4f7f\u7528 Map \u4f86\u7d00\u9304\u6bcf\u4e00\u500b\u5b57\u5143\u5c0d\u61c9\u7684 Soundex Code\uff0c\u4e26\u4e14\u7528\u5b57\u5143\u7684\u65b9\u5f0f\u4f86\u7d00\u9304\uff0c\u9019\u6a23\u5b50\u53ef\u4ee5\u628a\u7b54\u6848\u4f7f\u7528\u5b57\u4e32\u7684\u65b9\u5f0f\u52a0\u8d77\u4f86\u3002Soundex Code \u4e2d\u6c92\u6709\u7684\u5b57\u5143\u5c31\u4e0d\u9700\u8981\u5ba3\u544a\uff0c\u9019\u4e9b\u5b57\u5143\u5728\u5ba3\u544a Map \u6642\u6703\u81ea\u52d5\u9810\u8a2d\u70ba 0\u3002<\/p>\n\n\n\n<p>\u5c0d\u6536\u5230\u5b57\u4e32\u7684\u6bcf\u4e00\u500b\u5b57\u5143\u505a\u5224\u65b7\uff0c\u5982\u679c\u76ee\u524d\u5b57\u5143\u7684 Soundex Code \u4e0d\u70ba 0\uff0c\u5247\u8981\u5224\u65b7\u9019\u500b\u5b57\u5143\u662f\u5426\u70ba\u7b2c\u4e00\u500b Soundex Code\uff0c\u53ef\u4ee5\u5728\u8ff4\u5708\u5916\u9762\u5ba3\u544a\u4e00\u500b\u5e03\u6797\u503c\u4f86\u78ba\u8a8d\uff0c\u5982\u679c\u70ba\u7b2c\u4e00\u500b Soundex Code\uff0c\u5247\u5c07\u5728\u8ff4\u5708\u5916\u9762\u5ba3\u544a\u7684\u5b57\u4e32 ans \u8b8a\u6578 (\u9810\u8a2d\u70ba &#8220;&#8221;) += Map[\u76ee\u524d\u5b57\u5143]\uff0c\u4e26\u4e14\u9084\u8981\u5728\u8ff4\u5708\u7684\u5916\u9762\u5ba3\u544a\u4e00\u500b\u5b57\u5143 last \u4ee3\u8868\u4e0a\u4e00\u500b Soundex Code\uff0c\u5c07 last \u8a2d\u70ba Map[\u76ee\u524d\u5b57\u5143]\u3002\u5982\u679c\u4e0d\u662f\u7b2c\u4e00\u500b Soundex Code \u5247\u8981\u5224\u65b7\u76ee\u524d\u7684 Soundex Code \u662f\u5426\u8207 last \u4e00\u81f4\uff0c\u5982\u679c\u4e0d\u4e00\u81f4\u7684\u8a71\u5c31\u8981\u5c07 ans += Map[\u76ee\u524d\u5b57\u5143]\uff0c\u4e26\u4e14\u8981\u5c07 last \u8a2d\u70ba\u65b0\u7684 Map[\u76ee\u524d\u5b57\u5143]\u3002<\/p>\n\n\n\n<p>\u5982\u679c Soundex Code \u70ba 0\uff0c\u4ee3\u8868\u4e4b\u5f8c\u7684\u8981\u91cd\u65b0\u505a\u5224\u65b7\uff0c\u6240\u4ee5\u8981\u5c07 last \u8a2d\u70ba &#8216;0&#8217;\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=e641\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge E641: Soundex<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\n#include &lt;map&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    map&lt;char, char&gt;MAP;\n    MAP[&#39;B&#39;] = &#39;1&#39;;\n    MAP[&#39;F&#39;] = &#39;1&#39;;\n    MAP[&#39;P&#39;] = &#39;1&#39;;\n    MAP[&#39;V&#39;] = &#39;1&#39;;\n    MAP[&#39;C&#39;] = &#39;2&#39;;\n    MAP[&#39;G&#39;] = &#39;2&#39;;\n    MAP[&#39;J&#39;] = &#39;2&#39;;\n    MAP[&#39;K&#39;] = &#39;2&#39;;\n    MAP[&#39;Q&#39;] = &#39;2&#39;;\n    MAP[&#39;S&#39;] = &#39;2&#39;;\n    MAP[&#39;X&#39;] = &#39;2&#39;;\n    MAP[&#39;Z&#39;] = &#39;2&#39;;\n    MAP[&#39;D&#39;] = &#39;3&#39;;\n    MAP[&#39;T&#39;] = &#39;3&#39;;\n    MAP[&#39;L&#39;] = &#39;4&#39;;\n    MAP[&#39;M&#39;] = &#39;5&#39;;\n    MAP[&#39;N&#39;] = &#39;5&#39;;\n    MAP[&#39;R&#39;] = &#39;6&#39;;\n    string str;\n    while (cin &gt;&gt; str) {\n        bool first = true;\n        string ans = &quot;&quot;;\n        char last;\n        for (int i = 0; i&lt;str.length(); i++) {\n            const char ch = str[i];\n            if (MAP[ch] != 0) {\n                if (first) {\n                    first = false;\n                    ans += MAP[ch];\n                    last = MAP[ch];\n                }\n                else {\n                    if (MAP[ch] != last) {\n                        ans += MAP[ch];\n                        last = MAP[ch];\n                    }\n                }\n            }\n            else last = &#39;0&#39;;\n        }\n        cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge E641\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 10260 &#8211; Soundex Soundex \u7de8\u78bc\u6839\u64da\u62fc\u5beb\u5c07\u807d\u8d77\u4f86\u76f8\u4f3c\u7684\u55ae\u8a5e\u7d44\u5408\u5728 [&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,8,11,34,9],"class_list":["post-1062","post","type-post","status-publish","format-standard","hentry","category-uva","tag-map","tag-8","tag-11","tag-34","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1062","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=1062"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1062\/revisions"}],"predecessor-version":[{"id":1064,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1062\/revisions\/1064"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}