Discuss / Python / 大体就这样

大体就这样

Topic source

90qn

#1 Created at ... [Delete] [Delete and Lock User]

貌似代码有点啰嗦啊。。。

    def _int(x,y):
        return x*10 + y
    def trs(s):
        return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s]
    n = 0;
  #  s1 = []
  #  s2 = []
    for _s in s:
        if _s == '.':
            s1 = s[:n]
            s2 = s[n+1:]
            break
        n = n+1
    def a2(x):
        sum = 1
        while x:
            sum = sum * 10
            x = x - 1
        return sum
    return reduce(_int,map(trs,s1))+reduce(_int,map(trs,s2))/a2(len(s2))

  • 1

Reply