链接:
https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1027
#include<cstdio>
#include<cstring>
#include<iostream>
#include <cmath>
using namespace std;
const int maxn = 1010;
char a[maxn],b[maxn];
int a1[maxn],b1[maxn],c[maxn<<1];
int main()
{
while(scanf("%s%s",a,b)!=EOF)
{
if(a[0]=='0'||b[0]=='0')
{
printf("0\n");
continue;
}
memset(c,0,sizeof(c));
int len1 = strlen(a),len2=strlen(b);
for(int i=0; i < len1; i++)
a1[i]=a[len1-i-1]-'0'; //反转
for(int i=0; i < len2; i++)
b1[i]=b[len2-i-1]-'0';
for(int i=0; i < len1; i++)
{
for(int j=0; j < len2; j++)
{
c[i+j] += a1[i] * b1[j]; //每个位都相乘
c[i+j+1] += c[i+j]/10; //进位
c[i+j] %= 10;
}
}
int i = len1+len2;
while(!c[i])
i--;
for( ; i >= 0; i--)
printf("%d",c[i]);
printf("\n");
}
return 0;
}