Example #1
0
def plus(va,vb):  
    app=va.find('.')  
    ap=app  
    if ap==-1:ap=len(va)  
    bpp=vb.find('.')  
    bp=bpp  
    if bp==-1:bp=len(vb)  
    if ap>bp:l=ap  
    else:l=bp  
    ar=len(va)-ap-1  
    if app==-1:ar=0  
    br=len(vb)-bp-1  
    if bpp==-1:br=0  
    if ar>br:m=ar  
    else:m=br  
    n=l+m+1  
    a=['5']*n  
    b=['5']*n  
    afor=l-ap+1  
    for i in va:  
        if i!='.':  
            a[afor]=i  
            afor+=1  
    bfor=l-bp+1  
    for i in vb:  
        if i!='.':  
            b[bfor]=i  
            bfor+=1  
    pab=l+1  
    chck=['5']*n  
    up=a  
    rsl=b  
    while up!=chck:  
        a=up  
        b=rsl  
        up=['5']*n  
        rsl=['5']*n  
        for i in range(n):  
            i+=1  
            out=see(a[-i],b[-i])  
            if out=='error':  
                print 'see .. crashed as supposed '  
                exit()  
            rsl[-i]=out[1]  
            if out[0]!='5':up[-i-1]=out[0]  
    re=''  
    j=0  
    for i in range(n):  
        re+=rsl[i]  
        if j==l:re+='.'  
        j+=1  
    return shape(re)  
Example #2
0
def plus(va, vb):
    app = va.find('.')
    ap = app
    if ap == -1: ap = len(va)
    bpp = vb.find('.')
    bp = bpp
    if bp == -1: bp = len(vb)
    if ap > bp: l = ap
    else: l = bp
    ar = len(va) - ap - 1
    if app == -1: ar = 0
    br = len(vb) - bp - 1
    if bpp == -1: br = 0
    if ar > br: m = ar
    else: m = br
    n = l + m + 1
    a = ['5'] * n
    b = ['5'] * n
    afor = l - ap + 1
    for i in va:
        if i != '.':
            a[afor] = i
            afor += 1
    bfor = l - bp + 1
    for i in vb:
        if i != '.':
            b[bfor] = i
            bfor += 1
    pab = l + 1
    chck = ['5'] * n
    up = a
    rsl = b
    while up != chck:
        a = up
        b = rsl
        up = ['5'] * n
        rsl = ['5'] * n
        for i in range(n):
            i += 1
            out = see(a[-i], b[-i])
            if out == 'error':
                print 'see .. crashed as supposed '
                exit()
            rsl[-i] = out[1]
            if out[0] != '5': up[-i - 1] = out[0]
    re = ''
    j = 0
    for i in range(n):
        re += rsl[i]
        if j == l: re += '.'
        j += 1
    return shape(re)
Example #3
0
		刚开始的赋值比较复杂,为了骗过初始的循环条件
    pab=l+1  
    chck=['5']*n  
    up=a  
    rsl=b  
    while up!=chck:  
        a=up  
        b=rsl  
        up=['5']*n  
        rsl=['5']*n  

		这里就是主体的,取出每一位的两个数对比
			然后赋值给out,将out的两位分别赋值给up和rsl
        for i in range(n):  
            i+=1  
            out=see(a[-i],b[-i])  
            if out=='error':  
                print 'see .. crashed as supposed '  
                exit()  
            rsl[-i]=out[1]  
            if out[0]!='5':up[-i-1]=out[0]  
    re=''  
    j=0  

	把小数点加回来,l是左边的整数长度
    for i in range(n):  
        re+=rsl[i]  
        if j==l:re+='.'  
        j+=1  

	格式化后返回值