POJ 2389

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <string>
 4 #define MAXN 300
 5 using namespace std;
 6 
 7 int tem[MAXN];
 8 
 9 void big_int_mul(string a,string b,string & ans);
10 
11 int main()
12 {
13     //freopen("acm.acm","r",stdin);    
14     string a;
15     string b;
16     string ans;
17     cin>>a>>b;
18     big_int_mul(a,b,ans);
19     cout<<ans<<endl;
20 }
21 
22 void big_int_mul(string a,string b,string & ans)
23 {
24     int len_1 = a.length();
25     int len_2 = b.length();
26     int len = a.length() + b.length();
27     int i;
28     int j;
29     for(i = 0; i < len_1; ++ i)
30     {
31         for(j = 0; j < len_2; ++ j)
32         {
33             tem[i+j+1] += (a[i]-'0')*(b[j] - '0');
34         }
35     }
36     for(i = len - 1; i > 0; -- i)
37     {
38         if(tem[i] >= 10)
39         {
40             tem[i-1] += tem[i]/10;
41             tem[i] %= 10;
42         }
43     }
44     j = 0; 
45     while(tem[j] == 0)
46     {
47         ++ j;
48     }
49     
50     for(; j < len; ++ j)
51     {
52         ans += char(tem[j]+'0');
53     }
54 }

 

转载于:https://www.cnblogs.com/gavinsp/p/4568392.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值