Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
105983 | 赵德明 | 高精度乘法 | C++ | 通过 | 100 | 0 MS | 276 KB | 769 | 2023-10-09 13:15:33 |
#include<bits/stdc++.h> using namespace std; int a[5005]; int main(){ int nlen,mlen; memset(a,-1,sizeof(a)); string n,m; cin>>n>>m; nlen=n.size(); mlen=m.size(); for(int i=nlen-1;i>-1;i--){ for(int j=mlen-1;j>-1;j--){ int t1=n[i]-'0'+0,t2=m[j]-'0'+0; int temp=t1*t2; if(a[mlen+nlen-i-j-1]==-1){ a[mlen+nlen-i-j-1]=temp; } else a[mlen+nlen-i-j-1]+=temp; } } int i=1; for(;i<5001;i++){ if(a[i]==-1) break; if(a[i]>=9){ if(a[i+1]==-1){ a[i+1]=a[i]/10; } else a[i+1]+=a[i]/10; a[i]%=10; } } i-=1; bool boo=1; for(int j=i;j>0;j--){ if(a[j]==0) a[j]=-1; else break; } for(;i>0;i--){ if(a[i]!=-1){ cout<<a[i]; boo=0; } } if(boo) cout<<"0"; return 0; }