伤心,60分(最后两个点没过)

P1303 A*B Problem

52hertz_yh @ 2024-03-20 13:49:20

#include<bits/stdc++.h>
using namespace std;
string a,b;
long long A[100000020],B[100000020],c[10000020],s,e,w,q;
int main() 
{
    cin>>a>>b;
    for(int i=0;i<a.size();i++)A[i]=a[i]-'0';
        for(int i=0;i<b.size();i++)B[i]=b[i]-'0';
    reverse(A,A+a.size());
    reverse(B,B+b.size());
    int y=a.size()+b.size();
    for(int i=0;i<a.size();i++)
    {
        for(int j=0;j<b.size();j++)
        {
            c[i+j]+=A[j]*B[i]+w;
            w=c[i+j]/10;
            c[i+j]%=10;
        }
        q=i+b.size();
        while(w)
        {
            c[q]=w;
            w=c[q]/10;
            c[q]%=10;
            q++;
        }
    }
    while(!c[y-1]&&y>1)y--;
    for(int i=y-1;i>=0;i--)cout<<c[i];
    return 0;
}

by jrlimuyang @ 2024-04-03 09:54:59

我也是啊


by wangqicheng1637 @ 2024-04-12 19:30:21

@52hertz_yh 把第3和第4个for<=后面改成y就过了


by 52hertz_yh @ 2024-04-16 12:56:57

@wangqicheng1637 感谢(虽然好久了) 我这么整的

#include<bits/stdc++.h>
using namespace std;
char a1[10001],b1[10001];
int a[10001],b[10001],i,x,len,j,c[10001];
int main ()
{
    cin>>a1>>b1;
    int lena=strlen(a1);
    int lenb=strlen(b1);
    for(i=1;i<=lena;i++)a[i]=a1[lena-i]-'0';
    for(i=1;i<=lenb;i++)b[i]=b1[lenb-i]-'0';
    for(i=1;i<=lenb;i++)
    for(j=1;j<=lena;j++)
    c[i+j-1]+=a[j]*b[i];
    for(i=1;i<lena+lenb;i++)
    if(c[i]>9)
    {
        c[i+1]+=c[i]/10;
        c[i]%=10;
    }
    len=lena+lenb;
    while(c[len]==0&&len>1)len--;
    for(i=len;i>=1;i--)cout<<c[i];
    return 0;
}

by yuanqiu @ 2024-04-17 16:44:52

c[i+j]+=A[j]*B[i]+w;

j,i反了吧,我是这个原因


by Retana @ 2024-04-20 20:50:40

我和你写法差不多,但是最后两个wa了,所以是什么原理


|