高精度乘法

#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
char a[10010], b[10010];
int A[10010], B[10010], C[10010];
int main() {
    cin >> a >> b;
    int la = strlen(a), lb = strlen(b),lc=la+lb;
    for (int i = 0; i < la;i++)A[la -i] = a[i] - '0';
    for (int i = 0; i < lb;i++)B[lb - i] = b[i] - '0';
    for(int i=1;i<=la;i++)
        for (int j = 1; j <= lb; j++) {
            C[i + j - 1] += A[i] * B[j];
            C[i + j] += C[i + j - 1] / 10;
            C[i + j - 1] %= 10;
        }
    //100*0=000
    while (C[lc] == 0 && lc > 1)lc--;
    for (int i = lc; i > 0; i--)
        cout << C[i];
}

高精度讲解:https://www.bilibili.com/video/BV1LA411v7mt?p=3

上一篇:洛谷2.7


下一篇:C++基础算法教程——高精度算法