记录编号 95483 评测结果 AAAAAAAAAAAA
题目名称 增强的乘法问题 最终得分 100
用户昵称 Gravatarnoier 是否通过 通过
代码语言 C++ 运行时间 0.003 s
提交时间 2014-04-06 21:59:37 内存使用 1.96 MiB
显示代码纯文本
#include<cstring>
#include<cstdio>
using namespace std;
FILE *in;
FILE *out;
char a[100], b[100];
int z[100], x[100];
int ans[200];
void zhuanhuan(void)
{
	memset(z, 0, sizeof(z));
	memset(x, 0, sizeof(x));
	int r = strlen(a);
	int t = strlen(b);
	for (int i = 100 - r, j = 0; i < 100; i++, j++)
		z[i] = a[j] - '0';
	for (int i = 100 - t, j = 0; j < 100; i++, j++)
		x[i] = b[j] - '0';
}
void mul(void)
{
	memset(ans, 0, sizeof(ans));
	for (int i = 99; i >= 0; i--)
		for (int j = 99, q = 100+i; j >= 0; j--, q--)
			ans[q] += z[i] * x[j];
	/*for (int i=0;i<200;i++)
	fprintf(out,"%d",ans[i]);
	fprintf(out, "\n");*/
	 for (int i = 199; i >= 0; i--)
	{
		if (i != 0)
			ans[i - 1] += ans[i] / 10;
		ans[i] = ans[i] % 10;
	}
}

int main()
{
	in = fopen("mul.in", "r");
	out = fopen("mul.out", "w");
	fscanf(in, "%s", &a);
	fscanf(in, "%s", &b);
	zhuanhuan();
	mul();
	bool temp = false;
	for (int i = 0; i < 200; i++)
	{
		if (ans[i] != 0)
			temp = true;
		if (temp)
			fprintf(out, "%d", ans[i]);
	}
	if (!temp) fprintf(out, "0\n");
	// fprintf(out,"%s\n",a);
	// fprintf(out,"%s\n",b);
	return 0;
}