测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
对每个测试用例输出1行,即A+B的值.
one + two = three four + five six = zero seven + eight nine = zero + zero =
3 90 96
def fun(a, l): larr = [] rarr = [] c=0 k=0 m = int(l/2) op = a[m] for i in a: c+=1 if c > m: rarr.append(i) elif c<m: larr.append(i) dig = ['zero','one' , 'two' ,'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'] for i in range(len(rarr)): for k in range(len(dig)): if i < len(rarr): if rarr[i] == dig[k]: rarr[i] = k if i < len(larr): if larr[i] == dig[k]: larr[i] = k #prit() return rarr, larr def fun2(a, b): m = len(a)-1 m1 = len(b)-1 e=0 f = 0 for i in a: if m < 0: break e += i*(10**m) m-=1 for i in b: if m1 < 0: break f += i*(10**m1) m1-=1 return e, f def add(a, l): r, l = fun(a, l) r.pop() res1, res2=fun2(r, l) res = res1+res2 print(res) while True: try: s = input().split() if s[0] == 'zero' and s[2] == 'zero': break a = len(s) add(s, a) except: break