<address id="bxxfd"><dfn id="bxxfd"></dfn></address>

<dl id="bxxfd"><video id="bxxfd"></video></dl>

<sub id="bxxfd"><delect id="bxxfd"><ins id="bxxfd"></ins></delect></sub>

      <address id="bxxfd"><var id="bxxfd"></var></address>
      <sub id="bxxfd"><dfn id="bxxfd"><ins id="bxxfd"></ins></dfn></sub>

      <form id="bxxfd"><listing id="bxxfd"></listing></form>

      <thead id="bxxfd"><delect id="bxxfd"><output id="bxxfd"></output></delect></thead>

      <thead id="bxxfd"><var id="bxxfd"><output id="bxxfd"></output></var></thead><sub id="bxxfd"><var id="bxxfd"><output id="bxxfd"></output></var></sub>
      <sub id="bxxfd"><var id="bxxfd"><ruby id="bxxfd"></ruby></var></sub>
      <address id="bxxfd"><dfn id="bxxfd"></dfn></address>

      LeetCode #11 简单题(给定了范围,直接硬编码就好了。。)

      题目:整数转罗马数字

      题解:范围限定在0-3999,硬编码就好- -懒得想逻辑了

      class Solution {
      public:
          string intToRoman(int num) {
              int a = num / 1000;
              int b = (num / 100) % 10;
              int c = (num / 10) % 10;
              int d = num % 10;
              string ans;
              for (int i = 0; i < a; ++i)ans = ans + "M";
              if (b == 9)ans = ans + "CM";
              else if (b == 8)ans = ans + "DCCC";
              else if (b == 7)ans = ans + "DCC";
              else if (b == 6)ans = ans + "DC";
              else if (b == 5)ans = ans + "D";
              else if (b == 4)ans = ans + "CD";
              else if (b == 3)ans = ans + "CCC";
              else if (b == 2)ans = ans + "CC";
              else if (b == 1)ans = ans + "C";
      
              if (c == 9)ans = ans + "XC";
              else if (c == 8)ans = ans + "LXXX";
              else if (c == 7)ans = ans + "LXX";
              else if (c == 6)ans = ans + "LX";
              else if (c == 5)ans = ans + "L";
              else if (c == 4)ans = ans + "XL";
              else if (c == 3)ans = ans + "XXX";
              else if (c == 2)ans = ans + "XX";
              else if (c == 1)ans = ans + "X";
      
              if (d == 9)ans = ans + "IX";
              else if (d == 8)ans = ans + "VIII";
              else if (d == 7)ans = ans + "VII";
              else if (d == 6)ans = ans + "VI";
              else if (d == 5)ans = ans + "V";
              else if (d == 4)ans = ans + "IV";
              else if (d == 3)ans = ans + "III";
              else if (d == 2)ans = ans + "II";
              else if (d == 1)ans = ans + "I";
      
              return ans;
          }
      };
      相关文章
      相关标签/搜索
      三十码期期必中√资料2020年香港马会最快手机报码开奖结果现场直播历史查询记录二四六天天好彩免费资料大全网