# A*B Problem
注意点:要考虑字符串输入为0的情况,数组要开大一点
## 题目背景
高精度乘法模板题。
## 题目描述
给出两个非负整数,求它们的乘积。
## 输入格式
输入共两行,每行一个非负整数。
## 输出格式
输出一个非负整数表示乘积。
## 样例 #1
### 样例输入 #1
```
1
2
```
### 样例输出 #1
```
2
```
## 提示
每个非负整数不超过 $10^{2000}$。
#include <iostream>
using namespace std;
#include <string.h>
#include <math.h>
int c[100001];
int a[10000], b[10000];
void strReserve(string s, int d[])
{
for (int i = 0; i < s.size(); i++)
{
d[s.size() - i] = s[i] - '0';
}
}
int main()
{
string s1, s2;
cin >> s1 >> s2;
if (s1 == "0" || s2 == "0")
{
cout << 0;
return 0;
}
strReserve(s1, a);
strReserve(s2, b);
int la = s1.size();
int lb = s2.size();
int lc = la + lb;
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;
}
}
while (c[lc] == 0 && lc >= 1)lc--;
for (int i = lc; i>0; i--)
{
cout << c[i];
}
return 0;
}