80!#1WA!

P1303 A*B Problem

tlzhy @ 2021-04-28 23:49:19

#include<iostream>
#include<algorithm>
#include<memory.h>
using namespace std;
typedef int hugeint [10000000];
hugeint a,b,c;

    void input(int a[])
    {
        memset(a,0,sizeof(a));
        string n;
        cin>>n;
        for(int i=n.size()-1;i>=0;i--)
        {
            a[++a[0]]=n[i]-'0';
        }
    }
    void print(int a[]){
        for(int i=a[0];i>0;i--)
        {
            cout<<a[i];
        }
        cout<<endl;
    }

    void m(int *a,int *b,int *c){
        memset(c,0,sizeof(c));
        c[0]=a[0]+b[0]-1;
        int i,j,jw=0;
        for(i=1;i<=a[0];i++)
            for(j=1;j<=b[0];j++)
            {
                c[i+j-1]+=a[i]*b[j];
            }
        for(i=1;i<=c[0];i++)
        {
            c[i]+=jw;
            jw=c[i]/10;
            c[i]%=10;
        }
        if(jw>0)c[++c[0]]=jw;
    }

int main(){
    input(a);
    input(b);
    m(a,b,c);
    print(c);

    return 0;
}

by RedreamMer @ 2021-04-29 07:15:11

没考虑一个乘数是0


by tlzhy @ 2021-05-01 00:26:34

@RedreamMer 咋办?


by AC_Boy @ 2021-05-04 17:19:27

@tlzhy 加个while while(c[lenc]==0 and lenc>1)//lenc是长度,c是答案 lenc--;


|