tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
18
Task/Roman-numerals-Encode/Python/roman-numerals-encode-3.py
Normal file
18
Task/Roman-numerals-Encode/Python/roman-numerals-encode-3.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
anums = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
|
||||
rnums = "M CM D CD C XC L XL X IX V IV I".split()
|
||||
|
||||
def to_roman(x):
|
||||
ret = []
|
||||
for a,r in zip(anums, rnums):
|
||||
n,x = divmod(x,a)
|
||||
ret.append(r*n)
|
||||
return ''.join(ret)
|
||||
|
||||
if __name__ == "__main__":
|
||||
test = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,25,30,40,
|
||||
50,60,69,70,80,90,99,100,200,300,400,500,600,666,700,800,900,
|
||||
1000,1009,1444,1666,1945,1997,1999,2000,2008,2010,2011,2500,
|
||||
3000,3999)
|
||||
|
||||
for val in test:
|
||||
print '%d - %s'%(val, to_roman(val))
|
||||
Loading…
Add table
Add a link
Reference in a new issue