- 高精度乘法
答案
- 2024-3-16 15:45:32 @
#include <bits/stdc++.h>
using namespace std;
int main()
{
char a1[101]={0},b1[101]={0};
int a[101]={0},b[101]={0},c[201]={0};
int lena=0,lenb=0,lenc=0,i=0,j=0,x=0,f=1;
cin>>a1>>b1;
if(a1[0]=='-')
{
f=-f;
strcpy(a1,&a1[1]);
}
if(b1[0]=='-')
{
f=-f;
strcpy(b1,&b1[1]);
}
lena=strlen(a1);
lenb=strlen(b1);
for(i=0;i<lena;i++) a[lena-i-1]=a1[i]-'0';
for(i=0;i<lenb;i++) b[lenb-i-1]=b1[i]-'0';
for (i=0;i<lena;i++)
{
x=0;
for(j=0;j<lenb;j++)
{
c[i+j]=a[i]*b[j]+x+c[i+j];
x=c[i+j]/10;
c[i+j]%=10;
}
c[i+lenb]=x;
}
lenc=lena+lenb;
while (c[lenc]==0&&lenc>0)
lenc--;
if(f==-1 && c[lenc]>0) cout<<'-';
for(i=lenc;i>=0;i--) cout<<c[i];
return 0;
}
1 comments
-
刘羿延 LV 9 @ 2024-5-19 18:48:06
啊啊啊啊啊啊啊啊啊啊1啊啊1啊啊1啊啊1啊啊1啊啊1啊啊1啊啊1啊啊啊啊啊啊啊啊啊啊啊安安安安安安安安啊啊啊啊啊啊啊啊
- 1
Information
- ID
- 1036
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 8
- Tags
- # Submissions
- 47
- Accepted
- 6
- Uploaded By