# 字符串相乘

<p>给定两个以字符串形式表示的非负整数&nbsp;<code>num1</code>&nbsp;和&nbsp;<code>num2</code>，返回&nbsp;<code>num1</code>&nbsp;和&nbsp;<code>num2</code>&nbsp;的乘积，它们的乘积也表示为字符串形式。</p><p><strong>示例 1:</strong></p><pre><strong>输入:</strong> num1 = &quot;2&quot;, num2 = &quot;3&quot;<strong><br />输出:</strong> &quot;6&quot;</pre><p><strong>示例&nbsp;2:</strong></p><pre><strong>输入:</strong> num1 = &quot;123&quot;, num2 = &quot;456&quot;<strong><br />输出:</strong> &quot;56088&quot;</pre><p><strong>说明：</strong></p><ol>	<li><code>num1</code>&nbsp;和&nbsp;<code>num2</code>&nbsp;的长度小于110。</li>	<li><code>num1</code> 和&nbsp;<code>num2</code> 只包含数字&nbsp;<code>0-9</code>。</li>	<li><code>num1</code> 和&nbsp;<code>num2</code>&nbsp;均不以零开头，除非是数字 0 本身。</li>	<li><strong>不能使用任何标准库的大数类型（比如 BigInteger）</strong>或<strong>直接将输入转换为整数来处理</strong>。</li></ol>

以下程序实现了这一功能，请你填补空白处内容：

```cpp
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
	string multiply(string num1, string num2)
	{
		string res(num1.length() + num2.length(), '0');
		for (int i = num2.length() - 1; i >= 0; i--)
		{
			int j, carry = 0;
			for (j = num1.length() - 1; j >= 0; j--)
			{
				_____________________;
			}
			res[i + j + 1] = carry + '0';
		}
		int i;
		for (i = 0; i < res.length() - 1; i++)
		{
			if (res[i] != '0')
			{
				break;
			}
		}
		return res.substr(i);
	}
};
```

## template

```cpp
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
	string multiply(string num1, string num2)
	{
		string res(num1.length() + num2.length(), '0');
		for (int i = num2.length() - 1; i >= 0; i--)
		{
			int j, carry = 0;
			for (j = num1.length() - 1; j >= 0; j--)
			{
				carry += (num1[j] - '0') * (num2[i] - '0') + (res[i + j + 1] - '0');
				res[i + j + 1] = carry % 10 + '0';
				carry /= 10;
			}
			res[i + j + 1] = carry + '0';
		}
		int i;
		for (i = 0; i < res.length() - 1; i++)
		{
			if (res[i] != '0')
			{
				break;
			}
		}
		return res.substr(i);
	}
};
```

## 答案

```cpp
carry += (num1[j] - '0') * (num2[i] - '0') + (res[i + j + 1] - '0');
res[i + j + 1] = carry % 10 + '0';
carry /= 10;
```

## 选项

### A

```cpp
carry += (num1[j] - '0') * (num2[i] - '0') + (res[i + j] - '0');
res[i + j] = carry % 10 + '0';
carry /= 10;
```

### B

```cpp
carry += (num1[j] - '0') * (num2[i] - '0') + (res[i + j] - '0');
res[i + j] = carry % 10 + '0';
carry %= 10;
```

### C

```cpp
carry += (num1[j] - '0') * (num2[i] - '0') + (res[i + j - 1] - '0');
res[i + j - 1] = carry % 10 + '0';
carry %= 10;
```