‘’’
求字符串中所有整数的最小和
输入字符串s,输出s中包含所有整数的最小和。
说明:
字符串s,只包含 a-z A-Z ±
合法的整数包括
1)正整数:一个或者多个0-9组成,如 0 2 3 002 102
2)负整数:负号 – 开头,数字部分由一个或者多个0-9组成,如 -0 -012 -23 -00023
输入描述
包含数字的字符串
输出描述
所有整数的最小和’‘’
def zhengshuzuixiaohe(s):
status=1
sum=0
temps='0'
for i in s:
if not i.isdigit():
sum+=int(temps)
if not i=='-':
status = 1
temps='0'
else:
status = 0
temps = '-'
continue
if status:
sum+=int(i)
else:
temps+=i
return sum
print(zhengshuzuixiaohe('bb102-0034-0d02aa'))