0
点赞
收藏
分享

微信扫一扫

ICPC:大数的乘法

乐百川 2022-02-02 阅读 71
c++

题目描述:

输入:

输出:

样例输入:

样例输出:

代码:

#include <bits/stdc++.h>

using namespace std;


int main()
{
    string a,b;
    cin>>a>>b;
    long long int temp[100000],result[100000];
    fill(result,result+sizeof(result)/sizeof(long long int),0);
    int total_weishu = 0;
    for(int i=0; i<b.length(); i++)
    {
        memset(temp,0,sizeof(temp));


        long long int up = 0;
        int temp_weishu = a.length()+i;
        for(int j=0; j<a.length(); j++)
        {
            up += (b[b.length()-i-1]-'0') * (a[a.length()-j-1]-'0');
            temp[i+j] = up%10;
            up/=10;
        }
        while(up)
        {
            temp[temp_weishu] = up%10;
            temp_weishu++;
            up/=10;
        }


        int result_weishu = 0;
        for(int j=0; j<temp_weishu; j++)
        {
            result[j] = result[j] + temp[j];
            result[j+1] += result[j]/10;
            result[j] = result[j]%10;
            if(result[j+1])
            {
                result_weishu = j+2;
            }
            else {
                result_weishu = j+1;
            }
        }
        total_weishu = max(result_weishu, total_weishu);


    }
    for(int i=total_weishu; i; i--)
    {
        cout<<result[i-1];
    }


    return 0;
}
举报

相关推荐

0 条评论