RE求调(本地正确)

P1303 A*B Problem

Wang20090501 @ 2024-06-29 13:09:13

a = input()[::-1]
b = input()[::-1]
_sum = 0
d = 0
e = 0
for i in a:
    e = 0
    for j in b:
        _sum += (int(i) * int(j)) * 10 ** (d + e)
        e += 1
    d += 1
print(_sum)

by xsh0613 @ 2024-07-03 11:29:19

@Wang20090501 不要写那么多

a=input()
b=input()
a=int(a)
b=int(b)
print(a*b)

by Wang20090501 @ 2024-07-03 20:09:02

我想用模拟方法实现


by Wang20090501 @ 2024-07-08 17:02:27

@xsh0613


by Gfx7894560123 @ 2024-07-20 21:26:15

@Wang20090501 用c++高精度实现可以用数组:

#include<bits/stdc++.h>
using namespace std;
string tim(string a,string b){
    if(a=="0"||b=="0") return "0";
    int l1=a.size(),l2=b.size(),x=0;
    string ans(l1+l2-1,'0');
    for(int i=l1-1;i>=0;i--){
        x=0;
        for(int j=l2-1;j>=0;j--){
            int c1=a[i]-'0',c2=b[j]-'0';
            x+=c1*c2+ans[i+j]-'0';
            ans[i+j]=x%10+'0';
            x/=10;
        }
        if(i) ans[i-1]+=x;
    }
    if(x) ans=to_string(x)+ans;
    return ans;
}
int main()
{   
    cin.tie(nullptr)->sync_with_stdio(0);
    string a,b;
    cin>>a>>b;
    cout<<tim(a,b);
    return 0;
}   

|