{"id":439,"date":"2024-05-03T13:39:26","date_gmt":"2024-05-03T05:39:26","guid":{"rendered":"https:\/\/seanxd.com\/?p=439"},"modified":"2024-05-03T13:39:28","modified_gmt":"2024-05-03T05:39:28","slug":"zerojudge-c044","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-c044\/","title":{"rendered":"ZeroJudge C044: What&#8217;s Cryptanalysis"},"content":{"rendered":"\n\n\n<h4 class=\"wp-block-heading\">\u540c\u984c\uff1aUVa 10008 &#8211; What&#8217;s Cryptanalysis<\/h4>\n\n\n\n<p class=\"\">\u5bc6\u78bc\u7ffb\u8b6f (Cryptanalysis) \u662f\u6307\u628a\u67d0\u500b\u4eba\u5beb\u7684\u5bc6\u6587 (Cryptographic Writing) \u52a0\u4ee5\u5206\u89e3\u3002\u9019\u500b\u7a0b\u5e8f\u901a\u5e38\u6703\u5c0d\u5bc6\u6587\u8a0a\u606f\u505a\u7d71\u8a08\u5206\u6790\u3002\u4f60\u7684\u4efb\u52d9\u5c31\u662f<strong>\u5beb\u4e00\u500b\u7a0b\u5f0f\u4f86\u5c0d\u5bc6\u6587\u4f5c\u7c21\u55ae\u7684\u5206\u6790<\/strong>\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>\u8f38\u5165\u7684\u7b2c 1 \u5217\u6709\u4e00\u500b\u6b63\u6574\u6578 N\uff0c\u4ee3\u8868\u4ee5\u4e0b\u6709\u591a\u5c11\u5217\u9700\u8981\u4f5c\u5206\u6790\u7684\u5bc6\u6587\u3002 \u63a5\u4e0b\u4f86\u7684 N \u5217\uff0c\u6bcf\u5217\u542b\u6709 0 \u6216\u591a\u500b\u5b57\u5143 (\u53ef\u80fd\u5305\u542b\u7a7a\u767d\u5b57\u5143)\u3002<\/td><td>\u6bcf\u5217\u5305\u542b\u4e00\u500b<strong>\u5927\u5beb\u5b57\u5143 (A\uff5eZ)<\/strong> \u548c\u4e00\u500b\u6b63\u6574\u6578\u3002\u9019\u500b\u6b63\u6574\u6578\u4ee3\u8868\u8a72\u5b57\u5143\u5728\u8f38\u5165\u4e2d\u51fa\u73fe\u7684\u6b21\u6578\u3002\u8f38\u5165\u4e2d<strong>\u5927\u5c0f\u5beb (\u4f8b\u5982\uff1aA \u53ca a) \u8996\u70ba\u76f8\u540c\u7684\u5b57\u5143<\/strong>\u3002\u8f38\u51fa\u6642\u8acb\u6309\u7167<strong>\u5b57\u5143\u51fa\u73fe\u7684\u6b21\u6578\u7531\u5927\u5230\u5c0f\u6392\u5217<\/strong>\uff0c\u5982\u679c\u67092\u500b\u4ee5\u4e0a\u7684\u5b57<strong>\u5143\u51fa\u73fe\u6b21\u6578\u76f8\u540c\u7684\u8a71\uff0c\u5247\u6309\u7167\u5b57\u5143\u7684\u5927\u5c0f<\/strong> (\u4f8b\u5982\uff1aA \u5728 H \u4e4b\u524d) \u7531\u5c0f\u5230\u5927\u6392\u5217\u3002 <br>\u8acb\u6ce8\u610f\uff1a\u5982\u679c\u67d0\u4e00\u5b57\u5143\u672a\u51fa\u73fe\u5728\u8f38\u5165\u4e2d\uff0c\u90a3\u4ed6\u4e5f\u4e0d\u61c9\u51fa\u73fe\u5728\u8f38\u51fa\u4e2d\u3002<\/td><\/tr><tr><td>3<br>This is a test.<br>Count me 1 2 3 4 5.<br>Wow!!!! Is this question easy?<\/td><td>S 7<br>T 6<br>I 5<br>E 4<br>O 3<br>A 2<br>H 2<br>N 2<br>U 2<br>W 2<br>C 1<br>M 1<br>Q 1<br>Y 1<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge C044 \u7bc4\u4f8b\u6e2c\u8cc7<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p class=\"\">\u5148\u4f7f\u7528\u4e00\u500b <strong>Map \u4f86\u5b58\u53d6\u6bcf\u4e00\u500b\u5b57\u5143\u51fa\u73fe\u7684\u6b21\u6578<\/strong>\uff0c\u53ef\u4ee5\u4f7f\u7528 <strong>isalpha \u4f86\u5224\u65b7\u76ee\u524d\u5b57\u5143\u662f\u5426\u70ba\u82f1\u6587\u5b57\u6bcd\uff0c\u4e26\u4f7f\u7528toupper\u4f86\u5c07\u82f1\u6587\u5b57\u6bcd\u8f49\u63db\u6210\u5927\u5beb\u7684\u578b\u614b\u505a Map \u7684 Key<\/strong>\u3002<\/p>\n\n\n\n<p class=\"\">\u518d\u4f86\u4f7f\u7528 for (auto it:Map)\uff0c\u4e26\u4e14\u518d\u5ba3\u544a\u4e00\u500b\u65b0\u7684 Map (Key: int\uff5cValue: Vector)\uff0c\u9019\u500b<strong>\u65b0\u7684 Map \u662f\u5b58\u6709\u54ea\u4e9b\u5b57\u5143\u51fa\u73fe\u5728\u540c\u4e00\u500b\u6b21\u6578\u4e0a<\/strong>\u3002\u56e0\u70ba\u984c\u76ee\u8981\u6c42\u8981\u7531\u5927\u6392\u5230\u5c0f\uff0c\u6240\u4ee5\u5c07<strong>\u6b21\u6578\u4e58\u4ee5-1\u4e26\u5c07\u5176\u5b57\u5143Push_Back\u5230\u65b0\u7684Map\u4e2d<\/strong>\u3002<\/p>\n\n\n\n<p class=\"\">\u8f38\u51fa\u6642\u4e5f\u662f\u7528 Auto \u8dd1\u65b0 Map \u7684\u8ff4\u5708\uff0c\u5148\u5c07<strong>\u65b0\u7684 Map \u7684 Vector \u9032\u884c\u6392\u5e8f<\/strong>\uff0c\u7136\u5f8c\u518d\u8dd1\u4e00\u500b\u65b0\u7684 Map \u4e2d Vector \u7684 For\u8ff4\u5708\uff0c\u5c07\u88e1\u9762\u7684\u5b57\u5143\u548c\u76ee\u524dKey\u4e58\u4ee5-1 (\u525b\u525b\u4e58\u4ee5-1\u73fe\u5728\u8981\u5fa9\u539f) \u9032\u884c\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=c044\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge C044: What&#8217;s Cryptanalysis<\/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;algorithm&gt;\n#include &lt;map&gt;\n#include &lt;vector&gt;\nusing namespace std;\n\npair&lt;int, char&gt; rtn (int a, char b)\n{\n    pair&lt;int, char&gt;tmp;\n    tmp.first = a;\n    tmp.second = b;\n    return tmp;\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N;\n    cin &gt;&gt; N;\n    string a;\n    getline(cin, a);\n    map&lt;char, int&gt;MAP;\n    for (int i = 0; i&lt;N; i++)\n    {\n        string str;\n        getline(cin, str);\n        for (int j = 0; j&lt;str.length(); j++)\n        {\n            if (isalpha(str[j])) MAP[toupper(str[j])]++;\n        }\n    }\n    map&lt;int, vector&lt;char&gt;&gt;ans;\n    for (auto it:MAP)\n    {\n        ans[it.second * -1].push_back(it.first);\n    }\n    for (auto it:ans)\n    {\n        vector&lt;char&gt;result = it.second;\n        int num = it.first * -1;\n        sort(result.begin(), result.end());\n        for (int i = 0; i&lt;result.size(); i++)\n        {\n            cout &lt;&lt; result[i] &lt;&lt; &quot; &quot; &lt;&lt; num &lt;&lt; &quot;\\n&quot;;\n        }\n    }\n}\n\n\/\/ZeroJudge C044\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u540c\u984c\uff1aUVa 10008 &#8211; What&#8217;s Cryptanalysis \u5bc6\u78bc\u7ffb\u8b6f (C [&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,8,11,9],"class_list":["post-439","post","type-post","status-publish","format-standard","hentry","category-uva","tag-map","tag-pair","tag-20","tag-8","tag-11","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/439","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=439"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/439\/revisions"}],"predecessor-version":[{"id":441,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/439\/revisions\/441"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}