60 求调

P1303 A*B Problem

molakeser @ 2024-10-05 15:57:27

一红一紫QWQ

#include <bits/stdc++.h>

using namespace std;
#define int long long 
const int N=505;
string aa,bb;
int lena,lenb,a[N],b[N],c[N];

signed main() {
    cin>>aa>>bb;
    lena=aa.length();
    lenb=bb.length();
    for(int i=1;i<=lena;i++){
        a[i]=aa[lena-i]-48;
    }
    for(int i=1;i<=lenb;i++){
        b[i]=bb[lenb-i]-48;
    }
    int lmx=lena+lenb;
    for(int i=1;i<=lena;i++){
        for(int j=1;j<=lenb;j++){
            c[i+j-1]+=a[i]*b[j];
        }
    }
    for(int i=1;i<lmx;i++){
        if(c[i]>=10){
            c[i+1]+=(c[i]/10);
            c[i]%=10;
        }
    }
    while(c[lmx]==0&&lmx>1)
        lmx--;
    for(int i=lmx;i>=1;i--){
        cout<<c[i];
    }
    return 0;
}

by litangzheng @ 2024-10-05 16:01:24

@molakeser 一眼就知数组开小了,建议看一下数据范围。


by molakeser @ 2024-10-05 16:28:12

现在80了-_-


by molakeser @ 2024-10-05 16:35:44

又100啦耶


by Shadow97 @ 2024-10-05 20:12:24

@molakeser 孩子的开心好简单


|