baojiaming01 @ 2023-01-27 15:32:23
#include<bits/stdc++.h>
using namespace std;
int a[20000001],b[20000001],c[20000001];
int main()
{
string s,s1;
cin>>s>>s1;
reverse(s.begin(),s.end());
reverse(s1.begin(),s1.end());
int lena=s.size()-1;
int lenb=s1.size()-1;
for(int i=0; i<=lena; i++) a[i]=s[i]-'0';
for(int i=0; i<=lenb; i++) b[i]=s1[i]-'0';
for(int i=0; i<=lena; i++)
{
for(int j=0; j<=lenb; j++)
{
c[i+j]=c[i+j]+a[i]*b[j];
c[i+j+1]=c[i+j]/10;
c[i+1]=c[i+j]%10;
}
}
int lenc=lena+lenb+1;
while(c[lenc]==0 && lenc>0) lenc--;
for(int i=lenc; i<=0; i++) cout<<c[i];
return 0;
}
by Hell0_W0rld @ 2023-01-27 15:39:07
你再检查一下输出的for循环。
for(int i=lenc; i<=0; i++)
为什么是i<=0
by Hell0_W0rld @ 2023-01-27 15:39:17
@guaiguai02
by baojiaming01 @ 2023-01-27 15:42:25
改了,成5个RE了
by Milthm @ 2023-01-27 15:47:27
《 for(int i=lenc; i<=0; i++) cout<<c[i];》
倒序输出是i--(
by Milthm @ 2023-01-27 15:47:37
@guaiguai02
by baojiaming01 @ 2023-01-27 15:50:57
又成10分了
by _fewq @ 2023-01-27 16:12:31
c[i+j+1]=c[i+j]/10;
c[i+1]=c[i+j]%10;
改成
c[i+j+1]+=c[i+j]/10;
c[i+j]=c[i+j]%10;