题解<<抄的时候改一下变量>>

C2023011 2024-08-07 12:46:07 2024-08-07 12:52:26

#include <bits/stdc++.h>

using namespace std;

const int N = 2010;

char str1[1010], str2[1010];

int num1[N], num2[N], num3[N];

void change(char *s, int num[])

{

int len = strlen(s);

for (int i = 0;i < len;i++)

{

	num[len - 1 - i] = s[i] - '0';

}

}

void print(int num[])

{

int len = N;

while (num[len] == 0 && len >= 1)

{

	len--;

}

for (int i = len; i >= 0; i--)

{

	cout << num[i];

}

}

int main()

{

cin >> str1 >> str2;

change(str1, num1);

change(str2, num2);

for (int i = 0; str1[i]; i++)

{

	for (int j = 0; str2[j]; j++)

	{


		num3[i + j] += num1[i] * num2[j];

	}

}

for (int i = 0; i < N - 1; i++)

{

	num3[i+1] += num3[i] / 10;

	num3[i] %= 10;

}

print(num3);

return 0;

}

共 1 条回复

C2024010

(^~^)