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

【模板】大数乘法(51nod 1027)

时间:2018-09-15 20:48:32      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:--   define   style   div   png   color   getc   swa   tmp   

技术分享图片

技术分享图片
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #define LL long long
 5 #define rg register
 6 #define N 200010
 7 using namespace std;
 8 int n,m,len,a[N],b[N],t[N];
 9 char s[N],s2[N];
10 inline int read(){
11     int k=0,f=1; char c=getchar();
12     while(c<0||c>9)c==-&&(f=-1),c=getchar();
13     while(0<=c&&c<=9)k=k*10+c-0,c=getchar();
14     return k*f;
15 }
16 int main(){
17     scanf("%s",s+1); scanf("%s",s2+1);
18     n=strlen(s+1); m=strlen(s2+1); len=n+m+1;
19     if(n<m){
20         for(rg int i=1;i<=m;i++) a[m-i+1]=s2[i]-0;
21         for(rg int i=1;i<=n;i++) b[n-i+1]=s[i]-0;
22         swap(n,m);
23     }
24     else{
25         for(rg int i=1;i<=n;i++) a[n-i+1]=s[i]-0;
26         for(rg int i=1;i<=m;i++) b[m-i+1]=s2[i]-0;
27     }
28     for(rg int i=1;i<=m;i++){
29         for(rg int j=1;j<=n;j++)
30         t[i+j-1]+=b[i]*a[j];
31     }
32     for(rg int i=1;i<=len;i++){
33         int tmp=t[i]/10;
34         t[i]-=tmp*10;
35         t[i+1]+=tmp;
36     }
37     while(!t[len]) len--;
38     for(rg int i=len;i;i--) printf("%d",t[i]); puts("");
39     return 0;
40 }
View Code

 

【模板】大数乘法(51nod 1027)

标签:--   define   style   div   png   color   getc   swa   tmp   

原文地址:https://www.cnblogs.com/DriverLao/p/9652041.html

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