0分悬棺求调

P1303 A*B Problem

wky_wsy @ 2024-10-06 09:17:20

1234WA #5RE

#include <bits/stdc++.h>
using namespace std;
#define int long long 
int a[1000],b[1000],c[1000];
string cheng(string s,string d){
    int ls=s.size(),ld=d.size();
    int lm=max(ls,ld);
    for(int i=0;i<ls;i++){
        a[i]=s[ls-1-i]-'0';
    }
    for(int i=0;i<ld;i++){
        b[i]=d[ld-1-i]-'0';
    }
    string z;
    int l=0;
    for(int i=0;i<lm;i++){
        c[i]=a[i]*b[i];
        c[i+1]+=c[i]/10;
        c[i]%=10;
    }
    for(int i=999;i>-1;i--){
        if(c[i]!=0){
            l=i+1;
            break;
        }
    }
    for(int i=l-1;i>-1;i--){
        z+=(char)(c[i]+'0');
    }
    return z;
}
signed main(){
    string a,b;
    cin>>a>>b;
    string z=cheng(a,b);
    cout<<z;
    return 0;
}

by liyuanxi_0214 @ 2024-10-06 09:22:48

把你的lm定义成ls+ld试试呢,然后把你数组开两倍


by liyuanxi_0214 @ 2024-10-06 09:33:24

乘的时候要单开一个双层循环


|