视频链接:
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N=100005; int A[N],B[N],C[N]; int la,lb,lc; void mul(int A[],int B[],int C[]){ for(int i=0; i<la; i++) for(int j=0; j<lb; j++) C[i+j] += A[i]*B[j]; //累加乘积 for(int i=0,t=0; i<lc; i++){ t += C[i]; C[i] = t % 10; //存余 t /= 10; //进位 } while(lc>0 && C[lc]==0) lc--; //处理前导0 } int main(){ string a,b; cin >> a >> b; la=a.size(); lb=b.size(); lc=la+lb; for(int i=la-1; ~i; i--) A[la-1-i]=a[i]-'0'; for(int i=lb-1; ~i; i--) B[lb-1-i]=b[i]-'0'; mul(A,B,C); for(int i=lc; ~i; i--) cout << C[i]; }
标签:lb,lc,高精度,int,la,--,include,503,乘法 From: https://www.cnblogs.com/dx123/p/16654640.html