【题目来源】:https://www.51nod.com
【题意】
简单的大数乘法。模板。。
【思路】
强行模拟,,,。
【代码】
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
char strOne[1000+10];
char strTwo[1000+10];
int arrAns[2000+10][2000+10];
int arrOne[1000+10];
int arrTwo[1000+10];
int res[2000+10];
int main()
{
scanf("%s",strOne);
scanf("%s",strTwo);
int lenOne=strlen(strOne);
int lenTwo=strlen(strTwo);
for(int i=lenOne-1; i>=0; i--)
arrOne[i]=strOne[lenOne-i-1]-'0';
for(int i=lenTwo-1; i>=0; i--)
arrTwo[i]=strTwo[lenTwo-i-1]-'0';
memset(arrAns,0,sizeof(arrAns));
for(int i=0; i<lenOne; i++)
{
int One=arrOne[i];
for(int j=0; j<lenTwo; j++)
{
int Two=arrTwo[j];
int ans=arrAns[i][j]+One*Two;
arrAns[i][j+1]+=ans/10;
arrAns[i][j]=ans%10;
}
}//每一位都乘
for(int j=0; j<=2*lenTwo; j++)//加起来
{
int p=0,q=j;
while(1)
{
res[j]+=arrAns[p][q];
p++;
q--;
if(p>lenOne||q<0)
{
break;
}
}
}
for(int i=0; i<2*lenTwo; i++)//进位
{
if(res[i]>9)
{
res[i+1]+=res[i]/10;
res[i]%=10;
}
}
int k;
for(k=2*lenTwo; k>=0&&res[k]==0; k--);
if(k==-1)
printf("0\n");//特判
else
{
for(int i=k; i>=0; i--)
printf("%d",res[i]);
printf("\n");
}
}