罗马数字与阿拉伯数字对应关系如下:
且“ii”表示2,“iii”表示3,“iv”表示4,“vi表示6”,“vii”表示7,“viii”表示8,“ix”表示9,其余的类似。
阿拉伯数转换成罗马数字
class solution(object):
def inttoroman(self, num):
"""
:type num: int
:rtype: str
"""
if not num:
return ""
out = ""
i = 3
while i >= 0:
out += self.get_roman(i,num//(10**i))
num %= (10**i)
i -= 1
return out
def get_roman(self,power,quotient):
power_to_roman = {0:["i","v","x"],1:["x","l","c"],2:["c","d","m"],3:["m"]}