c++整数转罗马数字

    string intToRoman(int num)
    {
      string number = "";
      string  str1[] ={"","I","II","III","IV","V","VI","VII","VIII","IX"};
      string  str10[] = {"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
      string str100[] ={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
      string str1000[] = {"","M","MM","MMM"};
      number += str1000[num / 1000];
    num = num % 1000;
    number += str100[num / 100];
    num = num % 100;
    number += str10[num / 10];
    num = num % 10;
    number += str1[num ];
    return number;
    }

作者:yxk-d

链接:https://leetcode.cn/problems/integer-to-roman/solution/chen-you-ya-by-yxk-d-2ggq/

来源:力扣(LeetCode)

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

c++整数转罗马数字_第1张图片

你可能感兴趣的:(c++,leetcode,开发语言)