码迷,mamicode.com
首页 > 其他好文 > 详细

poj 2389 大整数乘法

时间:2018-02-26 23:17:08      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:cout   技术分享   class   span   body   col   memset   stream   AC   

技术分享图片

 

#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;

int main()
{
    char str1[1000],str2[1000];
    cin>>str1>>str2;
    int sum[1000];
    memset(sum,0,sizeof(sum));
    int len1 = strlen(str1),len2 = strlen(str2);
    for(int i = len1-1;i>=0;i--)
        for(int j = len2-1;j>=0;j--)
            sum[1000-(len1+len2-2-i-j)-1] += (str1[i]-0)*(str2[j]-0);
    for(int i = 1000-1;i>=0;i--)
    {
        if(sum[i]>9)
            sum[i-1] += sum[i]/10;
        sum[i] %= 10;
    }
    int i = 0;
    while(sum[i]==0)
        i++;
    for(;i<1000;i++)
        cout<<sum[i];
     
}

 

poj 2389 大整数乘法

标签:cout   技术分享   class   span   body   col   memset   stream   AC   

原文地址:https://www.cnblogs.com/ZZUGPY/p/8476177.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!