提交时间:2023-10-09 13:05:14

运行 ID: 105968

#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; 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]; } return 0; }