两个大数相乘-python实现

来源:互联网 发布:极米z4x无限连 mac 编辑:程序博客网 时间:2024/05/22 15:47
def multiply_two_big_number(str1, str2):    result = [0] * (len(str1) + len(str2))    t1 = str1[::-1]    t2 = str2[::-1]    for i in range(len(t2)):        for j in range(len(t1)):            result[j + i] += int(t2[i]) * int(t1[j])    for k in range(len(result)):        if result[k] >= 10:            result[k+1] += result[k] / 10            result[k] = result[k] % 10    while result != [] and result[-1] == 0:        result = result[:-1]    if result == []: return 0    return "".join([str(i) for i in result[::-1]])