'commit'
This commit is contained in:
32
TangDou/AcWing/HighPrecision/793_mul.cpp
Normal file
32
TangDou/AcWing/HighPrecision/793_mul.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 1e5 + 10;
|
||||
int a[N], al;
|
||||
int b[N], bl;
|
||||
void mul(int a[], int &al, int b[], int &bl) {
|
||||
int t = 0;
|
||||
int c[N] = {0};
|
||||
for (int i = 0; i < al; i++)
|
||||
for (int j = 0; j < bl; j++)
|
||||
c[i + j] += a[i] * b[j];
|
||||
al += bl;
|
||||
for (int i = 0; i < al; i++) {
|
||||
t += c[i];
|
||||
a[i] = t % 10;
|
||||
t /= 10;
|
||||
}
|
||||
// 前导0
|
||||
while (al > 0 && a[al] == 0) al--;
|
||||
}
|
||||
|
||||
int main() {
|
||||
string x, y;
|
||||
cin >> x >> y;
|
||||
for (int i = x.size() - 1; i >= 0; i--) a[al++] = x[i] - '0';
|
||||
for (int i = y.size() - 1; i >= 0; i--) b[bl++] = y[i] - '0';
|
||||
|
||||
mul(a, al, b, bl);
|
||||
for (int i = al; i >= 0; i--) printf("%d", a[i]);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user