Source of the topic:
https://leetcode.com/problems/integer-to-roman/
Test Instructions Analysis:
The problem is to convert the numbers in the interval [1-3999] into Roman numerals.
Topic Ideas:
As long as you know how Roman numerals and Arabic numerals are converted, it is not difficult to note that the 900,500,400,90,50,40,9,5,4 should be ' CM ', ' D ', ' CD ', ' XC ', ' L ', ' XL ', ' IX ', ' V ', ' IV '.
Code (Python):
1 classsolution (object):2 defInttoroman (self, num):3 """4 : Type Num:int5 : Rtype:str6 """7A = [1000,900,500,400,100,90,50,40,10,9,5,4,1]8b = ['M','CM','D','CD','C','XC','L','XL','X','IX','V','IV','I']9Ans ="'Teni =0 OneCount =0 A whilenum >0: -Count = num/A[i] -Num%=A[i] the whileCount >0: -Ans + =B[i] -Count-= 1 -i + = 1 + returnAns
View Code
Reprint Please specify source: http://www.cnblogs.com/chruny/p/4817819.html
[Leetcode] (python): 012-integer to Roman