leetcode第12题

# coding=utf-8
# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
class Solution(object):
    def intToRoman(self, num):
        """
        :type num: int
        :rtype: str

        建个字典,肯定的
        """
        I_dict={0:'',1:'I',2:'II',3:'III',4:'IV',5:'V',6:'VI',7:'VII',8:'VIII',9:'IX'}
        X_dict={0:'',1:'X',2:'XX',3:'XXX',4:'XL',5:'L',6:'LX',7:'LXX',8:'LXXX',9:'XC'}
        C_dict={0:'',1:'C',2:'CC',3:'CCC',4:'CD',5:'D',6:'DC',7:'DCC',8:'DCCC',9:'CM'}
        M_dict={0:'',1:'M',2:'MM',3:'MMM'}
        def I2X(num_a):#num%10是余数,num/10是商
            return num_a%10,num_a/10
        if num<10:
            int_o,b=I2X(num)
            str_fin=I_dict[int_o]
        elif num<100:
            int_t, int_o = I2X(num)
            str_t=I_dict[int_t]
            str_o=X_dict[int_o]
            str_fin=str_o+str_t
        elif num<1000:
            int_o, int_t = I2X(num)
            print int_t, int_o
            int_t,int_h=I2X(int_t)
            print int_t,int_o
            str_h=C_dict[int_h]
            str_t=X_dict[int_t]
            str_o=I_dict[int_o]
            str_fin=str_h+str_t+str_o
        else:
            int_o, int_t = I2X(num)
            int_t, int_h = I2X(int_t)
            int_h, int_th = I2X(int_h)
            str_h=C_dict[int_h]
            str_t=X_dict[int_t]
            str_o=I_dict[int_o]
            str_th=M_dict[int_th]
            str_fin=str_th+str_h+str_t+str_o
        return str_fin
a=Solution()
print a.intToRoman(10)

很长,也很常规

上一篇:干货|移动端App自动化之触屏操作自动化


下一篇:干货|移动端App自动化之触屏操作自动化