模拟乘法。 注意用longlong存数据。
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
void PrintLine(int len)
{
while (len--)
printf("-");
printf("\n");
}
int main(void)
{
long long x,y;
int num = 1;
while (scanf("%lld %lld", &x, &y))
{
if (x==0&&y==0)
break;
printf("Problem %d\n",num++);
long long s, ss, yy;
int f=0;
s = x*y;
ss=s;
yy=y;
int len = 0;
while (ss)
{
len++;
ss/=10;
}
int lenx = (int)log10(x)+1;
int leny = (int)log10(y)+1;
for (int i = 0; i < len-lenx; i++)
printf(" ");
printf("%lld\n",x);
for (int i = 0; i < len-leny; i++)
printf(" ");
printf("%lld\n",y);
PrintLine(len);
int p = 0, t=0;
s = 1;
while (yy)
{
while (yy%10==0)
{
yy/=10;
p++;
t++;
}
s = s * (yy%10) * x;
yy/=10;
int lens = (int)log10(s)+1;
for (int i = 0; i < len-lens-p; i++)
printf(" ");
printf("%lld",s);
for (int i = 0; i < t; i++)
printf("0");
printf("\n");
s = 1;
f++;
t=0;
p++;
}
if (f>1)
{
PrintLine(len);
s = x*y;
printf("%lld\n",s);
}
}
return 0;
}