80分了,最后一个数据没过,大佬帮看一看

P1303 A*B Problem

qew12312 @ 2023-10-24 22:27:49

#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
int as[700],bs[700],c[1400];
int main(){

    memset(as,0,sizeof(as));
    memset(bs,0,sizeof(bs));
    memset(c,0,sizeof(c));
    string s1,s2;
    cin>>s1;
    cin>>s2;
    int a1,a2;
    a1=s1.length();
    a2=s2.length();
    if(s1[0]=='0'||s2[0]=='0'){
        cout<<"0";
        return 0;
    }
    for(int i=0,s=a1-1;s>=0;s--,i++){
        as[i]=s1[s]-'0';
    }
    for(int i=0,s=a2-1;s>=0;s--,i++){
        bs[i]=s2[s]-'0';
    }
    int qw=0,i,we;
    for( i=0;i<=a1-1;i++){
        for(we=0;we<=a2-1;we++){
            qw=i+we;
        c[qw]+=as[i]*bs[we];
        if(c[qw]>=10)
        {
            c[qw+1]+=c[qw]/10;
            c[qw]%=10;
        }
    }}
if(c[qw]>0) qw++;
qw--;
while(c[qw]==0&&qw>0) qw--;
    for(;qw>=0;qw--){
        cout<<c[qw];
    }

    return 0;
}

by Y_QWQ_Y @ 2023-12-06 22:22:29

大哥,数组开小了,最大会有10的2000次方,你开700的数组是想去干啥?


|