标签:lis 输入 字符串 CM bsp col pre ict class
def Rome(x): dict={ ‘I‘:1, ‘V‘:5, ‘X‘:10, ‘L‘:50, ‘C‘:100, ‘D‘:500, ‘M‘:1000 } z=list(x) print(z) sum=0 for i in z: sum=sum+dict[i] if ‘IV‘ in x or ‘IX‘in x: num = x.count(‘IV‘)+x.count(‘IX‘) sum = sum - num * 2 if ‘XL‘ in x or ‘XC‘in x: num=x.count(‘XL‘)+x.count(‘XC‘) sum=sum-num*20 if ‘CD‘ in x or ‘CM‘in x: num=x.count(‘CD‘)+x.count(‘CM‘) sum=sum-num*200 return sum
标签:lis 输入 字符串 CM bsp col pre ict class
原文地址:https://www.cnblogs.com/Aprilnn/p/9196100.html