实在看不出来哪里错了......

P1303 A*B Problem

Mirrol @ 2024-02-21 23:14:53

#include<bits/stdc++.h>
#include<iostream>
#define _MAX 100001
using namespace std;
char s1[_MAX],s2[_MAX];
int a[_MAX],b[_MAX],c[_MAX];
void mul_hi(char *s1,char *s2);
int main(){
    cin>>s1>>s2;
    mul_hi(s1,s2);
    return 0;
}
void mul_hi(char *s1,char *s2){
    int la=strlen(s1),lb=strlen(s2),lc=la+lb;
    for(int i=1;i<=la;i++) a[i]=s1[la-i]-'0';
    for(int i=1;i<=lb;i++) b[i]=s2[lb-i]-'0';
    for(int i=1;i<=la;i++){
        for(int j=1;j<=lb;j++){
            c[i+j-1]+=a[i]*b[i];    
        }
    }
    for(int i=1;i<lc;i++){
        if(c[i]>9){
            c[i+1]+=c[i]/10;
            c[i]%=10; 
        }
    }
    while(c[lc]==0) lc--;
    for(int i=lc;i>0;i--) cout<<c[i];
    if(lc<1) cout<<"0";
    return;
}

IN:10 20

OUT:220


|