社区讨论
萌新第一次使用python提交总是RE
学术版参与者 4已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @lo99jie4
- 此快照首次捕获于
- 2023/10/28 07:47 2 年前
- 此快照最后确认于
- 2023/10/28 07:47 2 年前
RT
写的大整数乘法打算提交A*B
PYTHONimport matplotlib
def getDigits(x):
return [ int(a) for a in str(x) ]
def makeInt(digits):
return sum( [ 10**(len(digits)-i-1)*digits[i] for i in range(len(digits))])
def divideAndConquerMult1( X, Y ):
return divideAndConquerMult1_helper( getDigits(X), getDigits(Y) )
def divideAndConquerMult1_helper( x, y ):
n = max( len(x), len(y) )
while len(x) < n:
x.insert(0,0)
while len(y) < n:
y.insert(0,0)
if n == 1:
return x[0]*y[0]
mid = round(n/2)
xhigh = x[:mid]
xlow = x[mid:]
yhigh = y[:mid]
ylow = y[mid:]
highhigh = divideAndConquerMult1_helper( xhigh , yhigh )
highlow = divideAndConquerMult1_helper( xhigh , ylow )
lowhigh = divideAndConquerMult1_helper( xlow , yhigh )
lowlow = divideAndConquerMult1_helper( xlow , ylow )
HH = getDigits(highhigh) + [ 0 for i in range(2*(n - mid))]
MID = getDigits(lowhigh + highlow) + [0 for i in range(n-mid)]
LL = getDigits(lowlow)
result = makeInt(HH) + makeInt(MID) + makeInt(LL)
return result
a = input()
b = input()
print(divideAndConquerMult1(a,b))
回复
共 4 条回复,欢迎继续交流。
正在加载回复...