codevs_3117 高精度练习之乘法(my struct)

#include<bits/stdc++.h>
using namespace std;
string x,y;
int a[510],b[510],c[1010];
void mul(int a[],int b[]){
for(int i=1;i<=a[0];i++)
for(int j=1;j<=b[0];j++)c[i+j-1]+=a[i]*b[j];
for(int i=1;i<=c[0];i++){c[i+1]+=c[i]/10; c[i]%=10;}
while(!c[c[0]] && c[0]>1)c[0]--;
}
int main(){
cin>>x>>y;
a[0]=x.size(); b[0]=y.size(); c[0]=a[0]+b[0];
for(int i=1;i<=a[0];i++)a[i]=x[a[0]-i]-'0';
for(int i=1;i<=b[0];i++)b[i]=y[b[0]-i]-'0';
mul(a,b);
for(int i=c[0];i;i--)printf("%d",c[i]);
puts("");
return 0;
}
posted @ 2017-06-26 13:31  wqtnb_tql_qwq_%%%  阅读(377)  评论(0编辑  收藏  举报