大整数乘法 采用模拟竖式 计算方法进行表示
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <cctype>
#include <algorithm>
#include <cmath>
using namespace std;
///
#define INF 0xffffff7
#define MAXN 2000
///
int n;
unsigned an1[MAXN + 10];
unsigned an2[MAXN + 10];
unsigned aResult[MAXN * 2 + 10];
char szlines1[MAXN + 10];
char szlines2[MAXN + 10];
int main()
{
///
int i, j, th;
while (gets(szlines1) != NULL)
{
gets(szlines2);
int nlen1 = strlen(szlines1);
memset(an1, 0, sizeof(an1));
memset(an2, 0, sizeof(an2));
memset(aResult, 0, sizeof(aResult));
j = 0;
for (i = nlen1 - 1; i >= 0; i--)
{
an1[j++] = szlines1[i] - '0';
}
int nlen2 = strlen(szlines2);
j = 0;
for (i = nlen2 - 1; i >= 0; i--)
{
an2[j++] = szlines2[i] - '0';
}
for (i = 0; i < nlen2; i++)
{
for (j = 0; j < nlen1; j++)
{
aResult[i + j] += an2[i] * an1[j];
}
}
//处理进位
for (i = 0; i < MAXN * 2; i++)
{
if (aResult[i] >= 10)
{
aResult[i + 1] += aResult[i] / 10;
aResult[i] %= 10;
}
}
//输出结果
bool flag = false;
for (i = MAXN * 2; i >= 0; i--)
{
if (flag)
{
printf("%d", aResult[i]);
}
else if (aResult[i])
{
printf("%d", aResult[i]);
flag = true;
}
}
if (!flag)
{
printf("0\n");
}
else
printf("\n");
}
///
return 0;
}