社区讨论

都开到4020了怎么还RE

P1303A*B Problem参与者 4已保存回复 5

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
5 条
当前快照
1 份
快照标识符
@lo7sc64t
此快照首次捕获于
2023/10/27 06:58
2 年前
此快照最后确认于
2023/10/27 06:58
2 年前
查看原帖
CPP
#include<iostream>
#include<cstring>
using namespace std;
int a[2015], b[2005], ans[4020];
void rstring(char s1[], char s2[])
{
	a[0] = strlen(s1);
	b[0] = strlen(s2);
	for (int i = a[0], j = 0; i >= 1; i--, j++)
	{
		a[i] = s1[j] - '0';
	}
	for (int i = b[0], j = 0; i >= 1; i--, j++)
	{
		b[i] = s2[j] - '0';
	}
	return;
}
void multiplication(int a[], int b[])
{
	for (int i = 1; i <= a[0]; i++)
	{
		for (int j = 1; j <= b[0]; j++)
		{
			ans[i + j - 1] = ans[i + j - 1] + a[i] * b[j];
			ans[i + j] += ans[i + j - 1] / 10;
			ans[i + j - 1] = ans[i + j - 1] % 10;
		}
	}
	ans[0] = a[0] + b[0];
	return;
}
void print(int ans[])
{
	int len = ans[0];
	while (ans[len] == 0 && len != 1)
	{
		len--;
	}
	while (len > 0)
	{
		cout << ans[len--];
	}
	return;
}
int main()
{
	char s1[1005], s2[1005];
	cin >> s1 >> s2;
	rstring(s1, s2);
	multiplication(a, b);
	print(ans);
	return 0;
}

回复

5 条回复,欢迎继续交流。

正在加载回复...