luolie0804 @ 2023-12-18 20:56:57
#include<bits/stdc++.h>
using namespace std;
int a1[1005],a2[1005],b[1005];
int main()
{
string s1,s2;
cin>>s1>>s2;
reverse(s1.begin(),s1.end());
reverse(s2.begin(),s2.end());
if(s1=="0"||s2=="0")
{
cout<<0;return 0;
}
for(int i=0;i<s1.size();i++)
{
a1[i]=s1[i]-'0';
}
for(int i=0;i<s2.size();i++)
{
a2[i]=s2[i]-'0';
}
int t=s1.size()+s2.size()-1;
for(int i=0;i<s1.size();i++)
{
for(int j=0;j<s2.size();j++)
{
b[i+j]+=a1[i]*a2[j];
}
}
int jw=0;
for(int i=0;i<t;i++)
{
b[i]+=jw;
jw=b[i]/10;
b[i]%=10;
}
while(jw!=0)
{
t++;
b[t-1]=jw;
jw/=10;
}
while(t!=0&&b[t-1]==0) t--;
for(int i=t-1;i>=0;i--)
{
cout<<b[i];
}
return 0;
}
by __qkj__ @ 2023-12-18 21:00:03
@luolie0804 数组开小了
by Ahws_rwhy @ 2023-12-18 21:00:24
+1
by Robin_Yhj @ 2023-12-18 21:01:13
+1
by luolie0804 @ 2023-12-18 21:02:36
@hh6qkj @rwhy 大佬谢谢!!!