KiloCranes @ 2024-01-05 11:26:31
#include<bits/stdc++.h>
using namespace std;
const int N=2005;
char s1[N],s2[N];
int len_s1,len_s2,len_s=1,a1[N],a2[N],s[N];
int main(){
cin>>s1;
cin>>s2;
len_s1=strlen(s1);
len_s2=strlen(s2);
for(int i=0;i<len_s1;i++)
a1[i]=s1[len_s1-i-1]-'0';
for(int i=0;i<len_s2;i++)
a2[i]=s2[len_s2-i-1]-'0';
for(int i=0;i<len_s1;i++)
for(int j=0;j<len_s2;j++)
s[j+i]+=a1[i]*a2[j];
len_s=len_s1+len_s2;
for(int i=0;i<len_s;i++)
if(s[i]>=10){
s[i+1]+=s[i]/10;
s[i]%=10;
}
while(s[len_s-1]==0&&len_s>1)
len_s--;
for(int i=len_s-1;i>=0;i--)
cout<<s[i];
return 0;
}
by Ja50nY0un9_as_AgNO3 @ 2024-01-05 11:48:50
主页双帖
危
by sherry_lover @ 2024-01-05 11:50:21
每个整数有2000位,乘起来最多有4000为,建议把N的初始值改成4005
@KiloCranes
by KiloCranes @ 2024-01-05 12:08:00
@sherry_lover 谢谢!