def str2float(s):
def str2int(s):
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '.': '.', '-': '-'}
return DIGITS[s]
def mul(x, y):
return x * 10 + y
def div(x, y):
return x / 10 + y
def str2list(s):
if s.find('.') == -1:
return list(map(str2int, s)), []
else:
return list(map(str2int, s[:s.find('.')])), list(map(str2int, s[s.find('.') + 1:]))
a, b = str2list(s)
if a[0] == '-':
int = -reduce(mul, a[1:])
if (b == []) | (len(b) == b.count(0)):
return int
b.reverse()
return int - reduce(div, b) / 10
int = reduce(mul, a)
return int + reduce(div, b) / 10
Sign in to make a reply
简简单单rsi
def str2float(s):
def str2int(s):
DIGITS = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '.': '.', '-': '-'}
return DIGITS[s]
def mul(x, y):
return x * 10 + y
def div(x, y):
return x / 10 + y
def str2list(s):
if s.find('.') == -1:
return list(map(str2int, s)), []
else:
return list(map(str2int, s[:s.find('.')])), list(map(str2int, s[s.find('.') + 1:]))
a, b = str2list(s)
if a[0] == '-':
int = -reduce(mul, a[1:])
if (b == []) | (len(b) == b.count(0)):
return int
else:
b.reverse()
return int - reduce(div, b) / 10
else:
int = reduce(mul, a)
if (b == []) | (len(b) == b.count(0)):
return int
else:
b.reverse()
return int + reduce(div, b) / 10