全wa??

P1303 A*B Problem

Mr_LLLiao @ 2020-09-11 23:05:07

看了看自己错的地方 in:0 10 out: 0 ????? 我原地懵逼啊!!!


by a_bad_seed @ 2020-10-10 21:19:41

@Mr_LLLiao AC的(仅供参考)

#include <bits/stdc++.h>
using namespace std;
int main() {
    string s1,s2;
    int a[100001]= {0};
    int b[100001]= {0};
    int c[100001]= {0};
    int x=0;
    int i,j;
    cin>>s1>>s2;
    int lena=s1.size();
    int lenb=s2.size();
    int lenc=0;
    for(i=0; i<lena; i++) {
        a[i]=s1[lena-i-1]-'0';
    }
    for(i=0; i<lenb; i++) {
        b[i]=s2[lenb-i-1]-'0';
    }
    for(i=0; i<lena; i++) {
        for(j=0; j<lenb; j++) {
            c[i+j]+=a[i]*b[j];
        }
    }
    for(i=0; i<lena+lenb; i++) {
        if(c[i]>=10) {
            c[i+1]+=c[i]/10;
            c[i]%=10;
        }
    }
    lenc=lena+lenb;
    while(lenc>0&&c[lenc]==0) {
        lenc--;
    }
    for(i=lenc; i>=0; i--) {
        cout<<c[i];
    }
    return 0;
}

|