60分求助 最后两点没过

P1303 A*B Problem

bajia @ 2023-09-22 21:55:27

#include<bits/stdc++.h>
using namespace std;
int main(){
    string sa,sb;
    cin>>sa>>sb;
    int i,j,jw;
    int la=sa.size(),lb=sb.size(),lc,a[2000],b[2000],c[4000]={0};
    for(i=0;i<la;i++) a[la-i]=sa[i]-'0';
    for(i=0;i<lb;i++) b[la-i]=sb[i]-'0';
    for(i=1;i<=la;i++){
        jw=0;
        for(j=1;j<=lb;j++){
            c[i+j-1]+=a[i]*b[j]+jw;
            jw=c[i+j-1]/10;
            c[i+j-1]%=10;
        }
        c[i+lb]=jw;
    }
    lc=la+lb;
    while(lc>1&&c[lc]==0) lc--;
    for(i=lc;i>=1;i--) cout<<c[i];
    return 0;
}

by Sreffial @ 2023-09-22 22:06:00

应该是 b[lb-i] 而不是 b[la-i]。

for(i=0;i<la;i++) a[la-i]=sa[i]-'0';
for(i=0;i<lb;i++) b[lb-i]=sb[i]-'0';

by Sreffial @ 2023-09-22 22:08:16

@bajia


by bajia @ 2023-09-22 22:13:07

@Sreffial thank you


by Sreffial @ 2023-09-22 22:13:57

@bajia 没事(


|