2014年3月8日 星期六

[Python] Roman Numerals Converter

Speedy solution:

1:  def checkio(input):  
2:    ints = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)  
3:    nums = ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')  
4:     
5:    result = ""  
6:    
7:    for i in range(len(ints)):  
8:       count = int(input / ints[i])  
9:       result += nums[i] * count  
10:      input -= ints[i] * count  
11:     
12:    return result  


ref . http://www.rapidtables.com/math/symbols/roman_numerals.htm

--

人家寫12行我寫108行,真 他媽的

沒有留言:

張貼留言