ylxatch @ 2024-12-28 22:53:58
#include <bits/stdc++.h>
using namespace std;
int la,lb,lc,a[1010],b[1010],c[1010];
char sa[1010],sb[1010];
int main(){
scanf("%s",sa);
scanf("%s",sb);
la=strlen(sa);
lb=strlen(sb);
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(int i=0;i<la;i++) a[la-i-1]=sa[i]-'0';
for(int i=0;i<lb;i++) b[lb-i-1]=sb[i]-'0';
memset(c,0,sizeof(c));
int jw=0,s,w;
for(int i=0;i<la;i++){
for(int f=0;f<=lb;f++){
s = a[i]*b[f];jw=s/10;s%=10;
w=i+f; c[w]=c[w]+s;
c[w+1]=c[w+1]+jw+c[w]/10;
c[w]%=10;
}
}
lc = la+lb;
while(c[lc]==0) lc--;
if(lc<0) printf("0\n");
else for(int i=lc;i>=0;i--) printf("%d",c[i]);
return 0;
}
by MoLing_111 @ 2024-12-28 23:47:28
数组小了
by gys006 @ 2024-12-29 19:31:30
@ylxatch
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int alen,blen,x[10001],y[10001],z[10001],len;
int main()
{
cin>>s1>>s2;
alen=s1.length();
blen=s2.length();
for(int i=0;i<=alen;i++)
{
x[i]=s1[alen-i-1]-'0';
}
for(int i=0;i<=blen;i++)
{
y[i]=s2[blen-i-1]-'0';
}
len=alen+blen;
for(int i=0;i<alen;i++)
for(int j=0;j<blen;j++)
{
z[i+j]+=x[i]*y[j];
}
for(int i=0;i<len-1;i++)
{
z[i+1]+=z[i]/10;
z[i]%=10;
}
while(z[len-1]>9)
{
z[len]=z[len-1]/10;
z[len-1]%=10;
len++;
}
while(z[len-1]==0&&len>1)
len--;
for(int i=len-1;i>=0;i--)
cout<<z[i];
return 0;
}
求互关!!
by gys006 @ 2024-12-29 19:32:31
仅供参考!!
by ylxatch @ 2024-12-29 20:04:48
@gys006 感谢!已关ღ( ´・ᴗ・` )