{"id":1753,"date":"2022-01-11T16:07:43","date_gmt":"2022-01-11T08:07:43","guid":{"rendered":"http:\/\/139.9.1.231\/?p=1753"},"modified":"2022-01-11T16:07:44","modified_gmt":"2022-01-11T08:07:44","slug":"leetcodeday12","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/11\/leetcodeday12\/","title":{"rendered":"leetcodeday12&#8212;\u6574\u6570\u8f6c\u7f57\u9a6c\u6570\u5b57"},"content":{"rendered":"\n<p>\u7f57\u9a6c\u6570\u5b57\u5305\u542b\u4ee5\u4e0b\u4e03\u79cd\u5b57\u7b26\uff1a&nbsp;<code>I<\/code>\uff0c&nbsp;<code>V<\/code>\uff0c&nbsp;<code>X<\/code>\uff0c&nbsp;<code>L<\/code>\uff0c<code>C<\/code>\uff0c<code>D<\/code>&nbsp;\u548c&nbsp;<code>M<\/code>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u5b57\u7b26<\/strong>          <strong>\u6570\u503c<\/strong>\nI             1\nV             5\nX             10\nL             50\nC             100\nD             500\nM             1000<\/code><\/pre>\n\n\n\n<p>\u4f8b\u5982\uff0c \u7f57\u9a6c\u6570\u5b57 2 \u5199\u505a&nbsp;<code>II<\/code>&nbsp;\uff0c\u5373\u4e3a\u4e24\u4e2a\u5e76\u5217\u7684 1\u300212 \u5199\u505a&nbsp;<code>XII<\/code>&nbsp;\uff0c\u5373\u4e3a&nbsp;<code>X<\/code>&nbsp;+&nbsp;<code>II<\/code>&nbsp;\u3002 27 \u5199\u505a&nbsp;&nbsp;<code>XXVII<\/code>, \u5373\u4e3a&nbsp;<code>XX<\/code>&nbsp;+&nbsp;<code>V<\/code>&nbsp;+&nbsp;<code>II<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u7f57\u9a6c\u6570\u5b57\u4e2d\u5c0f\u7684\u6570\u5b57\u5728\u5927\u7684\u6570\u5b57\u7684\u53f3\u8fb9\u3002\u4f46\u4e5f\u5b58\u5728\u7279\u4f8b\uff0c\u4f8b\u5982 4 \u4e0d\u5199\u505a&nbsp;<code>IIII<\/code>\uff0c\u800c\u662f&nbsp;<code>IV<\/code>\u3002\u6570\u5b57 1 \u5728\u6570\u5b57 5 \u7684\u5de6\u8fb9\uff0c\u6240\u8868\u793a\u7684\u6570\u7b49\u4e8e\u5927\u6570 5 \u51cf\u5c0f\u6570 1 \u5f97\u5230\u7684\u6570\u503c 4 \u3002\u540c\u6837\u5730\uff0c\u6570\u5b57 9 \u8868\u793a\u4e3a&nbsp;<code>IX<\/code>\u3002\u8fd9\u4e2a\u7279\u6b8a\u7684\u89c4\u5219\u53ea\u9002\u7528\u4e8e\u4ee5\u4e0b\u516d\u79cd\u60c5\u51b5\uff1a<\/p>\n\n\n\n<ul><li><code>I<\/code>&nbsp;\u53ef\u4ee5\u653e\u5728&nbsp;<code>V<\/code>&nbsp;(5) \u548c&nbsp;<code>X<\/code>&nbsp;(10) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a 4 \u548c 9\u3002<\/li><li><code>X<\/code>&nbsp;\u53ef\u4ee5\u653e\u5728&nbsp;<code>L<\/code>&nbsp;(50) \u548c&nbsp;<code>C<\/code>&nbsp;(100) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a 40 \u548c&nbsp;90\u3002&nbsp;<\/li><li><code>C<\/code>&nbsp;\u53ef\u4ee5\u653e\u5728&nbsp;<code>D<\/code>&nbsp;(500) \u548c&nbsp;<code>M<\/code>&nbsp;(1000) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a&nbsp;400 \u548c&nbsp;900\u3002<\/li><\/ul>\n\n\n\n<p>\u7ed9\u4f60\u4e00\u4e2a\u6574\u6570\uff0c\u5c06\u5176\u8f6c\u4e3a\u7f57\u9a6c\u6570\u5b57\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>&nbsp;num = 3\n<strong>\u8f93\u51fa:<\/strong> \"III\"<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>&nbsp;num = 4\n<strong>\u8f93\u51fa:<\/strong> \"IV\"<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;3:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>&nbsp;num = 9\n<strong>\u8f93\u51fa:<\/strong> \"IX\"<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;4:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>&nbsp;num = 58\n<strong>\u8f93\u51fa:<\/strong> \"LVIII\"\n<strong>\u89e3\u91ca:<\/strong> L = 50, V = 5, III = 3.<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;5:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>&nbsp;num = 1994\n<strong>\u8f93\u51fa:<\/strong> \"MCMXCIV\"\n<strong>\u89e3\u91ca:<\/strong> M = 1000, CM = 900, XC = 90, IV = 4.<\/code><\/pre>\n\n\n\n<p>\u6211\u7684\u601d\u8def\uff1a\u5176\u5b9e\u5c31\u662f\u548c\u6211\u4eec\u7684123455\u6570\u5b57\u8868\u793a\u6cd5\u5dee\u4e0d\u591a\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e \u4e2a\u4f4d\u6570\uff1a\u7528 [&#8220;I&#8221;,&#8221;IV&#8221;,&#8221;V&#8221;,&#8221;IX&#8221;] \u4e2d\u7684\u5143\u7d20\u7ec4\u5408\u8868\u793a<\/p>\n\n\n\n<p>\u5341\u4f4d\u6570\uff1a \u7528  [&#8220;X&#8221;,&#8221;XL&#8221;,&#8221;L&#8221;,&#8221;XC&#8221;]  \u4e2d\u7684\u5143\u7d20\u7ec4\u5408\u8868\u793a \u3001<\/p>\n\n\n\n<p>\u767e\u4f4d\u6570\uff1a [&#8220;C&#8221;,&#8221;CD&#8221;,&#8221;D&#8221;,&#8221;CM&#8221;] <\/p>\n\n\n\n<p>\u5343\u4f4d\u6570\uff1a\u7528M\u8868\u793a<\/p>\n\n\n\n<p>\u56e0\u6b64\u904d\u5386\u6570\u4e2d\u7684\u6bcf\u4e00\u4f4d\uff0c\u5206\u522b\u7528\u76f8\u5e94\u7684\u5143\u7d20\u8868\u793a\uff0c\u7136\u540e\u5728\u7ec4\u88c5\u8d77\u6765\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc code=start\r\nclass Solution:\r\n    def intToRoman(self, num: int) -> str:\r\n        str2=str(num)\r\n        str0=&#91;\" \"]\r\n        str1=&#91;\"\",\"\",\"\",\"\"]\r\n        lens=len(str2)\r\n        if lens==4:\r\n            str0 = &#91;int(str2&#91;0])*\"M\"]\r\n            str2=str2&#91;1:]\r\n            lens=len(str2)\r\n        m=lens-1\r\n        mod=&#91;&#91;\"I\",\"IV\",\"V\",\"IX\"],&#91;\"X\",\"XL\",\"L\",\"XC\"],&#91;\"C\",\"CD\",\"D\",\"CM\"]]\r\n        for i  in range(lens):\r\n            j=int(str2&#91;i])\r\n    \r\n            if 0 &lt;= j &lt; 4:\r\n                str1&#91;i]=mod&#91;m]&#91;0]*j\r\n            elif j==4:\r\n                str1&#91;i]=mod&#91;m]&#91;1]\r\n            elif 4&lt;j&lt;9:\r\n                str1&#91;i]=mod&#91;m]&#91;2]+mod&#91;m]&#91;0]*(j-5)\r\n            elif j==9:\r\n                str1&#91;i]=mod&#91;m]&#91;3]\r\n            m=m-1\r\n        return (\"\".join(str0+str1)).strip()\r\n        \r\n# @lc code=end<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"758\" height=\"181\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-181.png\" alt=\"\" class=\"wp-image-1810\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-181.png 758w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-181-300x72.png 300w\" sizes=\"(max-width: 758px) 100vw, 758px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7f57\u9a6c\u6570\u5b57\u5305\u542b\u4ee5\u4e0b\u4e03\u79cd\u5b57\u7b26\uff1a&nbsp;I\uff0c&nbsp;V\uff0c&nbsp;X\uff0c&nbsp;L\uff0cC\uff0cD&nbsp;\u548c &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/11\/leetcodeday12\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday12&#8212;\u6574\u6570\u8f6c\u7f57\u9a6c\u6570\u5b57<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/1753"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=1753"}],"version-history":[{"count":2,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/1753\/revisions"}],"predecessor-version":[{"id":1811,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/1753\/revisions\/1811"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=1753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=1753"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=1753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}