首页 > 其他 > 详细

【LeetCode】12. Integer to Roman

时间:2016-12-22 06:46:42      阅读:141      评论:0      收藏:0      [点我收藏+]

Given an integer, convert it to a roman numeral.

Input is guaranteed to be within the range from 1 to 3999.

题意:把数字转换为罗马数字

感觉用c的话太麻烦了,所以用Python写了

 1 class Solution(object):
 2     def intToRoman(self, num):
 3         """
 4         :type num: int
 5         :rtype: str
 6         """
 7         flag=[[‘‘,I,II,III,IV,V,VI,VII,VIII,IX],
 8             [‘‘,X,XX,XXX,XL,L,LX,LXX,LXXX,XC],
 9             [‘‘,C,CC,CCC,CD,D,DC,DCC,DCCC,CM],
10             [‘‘,M,MM,MMM]]
11         
12         i = 0
13         s = ‘‘
14         
15         while num>0:
16             t = num%10
17             s = flag[i][t]+s
18             i+=1
19             num=num//10
20             
21         return s

 

【LeetCode】12. Integer to Roman

原文:http://www.cnblogs.com/fcyworld/p/6209590.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!