20pts求大佬条~QAQ

P1480 A/B Problem

_tao_tie_ @ 2025-01-11 18:46:35

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int l2,l1,i,j,c[20010],b[20010],a[20010],mx;
    string z1,z2; 
    memset(c,0,sizeof(c));
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    cin>>z1>>z2; 
    l1=z1.length();
    l2=z2.length();
    for(i=0;i<l1;i++)
        a[i]=z1[l1-1-i]-'0';
    for(i=0;i<l2;i++)
        b[i]=z2[l2-1-i]-'0';
    mx=l1+l2;
    for(i=0;i<l1;i++)
    {
        for(j=0;j<l2;j++)
        {
            c[i+j]+=b[j]*a[i];
            if(c[i+j]>=10)
            {
                c[i+j+1]+=c[i+j]/10;
                c[i+j]%=10;
            }
        }

    }
    while(c[mx]==0&&mx!=0)
        mx--;
    for(i=mx;i>=0;i--)
        cout<<c[i];
    return 0;
}

|