大佬求解!!!!

P1303 A*B Problem

Anubis @ 2018-07-06 10:22:39

这是代码,下载的测试数据都对,但就是WA 求助!!

include<algorithm>

include<cmath>

include<cstdio>

include<cstdlib>

include<cstring>

include<iostream>

include<vector>

using namespace std; int b[100000000]; char A1[200056],A2[200056]; int a1[11111111]; int a2[11111111]; int main(void) { gets(A1); gets(A2); int l1,l2; l1=strlen(A1); for(int i=l1-1; i>=0; --i) { int T; T=A1[i]-'0'; a1[l1-1-i]=T; } l2=strlen(A2); for(int i=l2-1; i>=0; --i) { int T; T=A2[i]-'0'; a2[l2-1-i]=T; } for(int i=0; i<l1 ; ++i) { for(int j=0; j<l2 ; ++j) { b[i+j]+=a1[i]*a2[j]; if(b[i+j]>=10) { b[i+j+1]+=b[i+j]/10; b[i+j]%=10; } } } bool y=1; for(int i=l1+l2-1; i>=0; --i) { if(b[i]!=0) { y=0; } if(b[i]==0&&y) { continue; } cout<<b[i]; } if(y) cout<<'0';

return 0;

}


by 初音ミク_Miku @ 2018-07-06 10:44:23


#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<vector>
using namespace std;
int b[100000000]; 
char A1[200056],A2[200056];
int a1[11111111]; 
int a2[11111111];
int main(void)
{
gets(A1); 
gets(A2);
int l1,l2;
l1=strlen(A1);
for(int i=l1-1; i>=0; --i) 
{
int T;
T=A1[i]-'0';
a1[l1-1-i]=T;
}
l2=strlen(A2); 
for(int i=l2-1; i>=0; --i)
{ 
int T; T=A2[i]-'0'; a2[l2-1-i]=T; 
}
for(int i=0; i<l1 ; ++i)
{
for(int j=0; j<l2 ; ++j) 
{
b[i+j]+=a1[i]*a2[j];
if(b[i+j]>=10)
{
b[i+j+1]+=b[i+j]/10; b[i+j]%=10;
}
} 
} bool y=1;
for(int i=l1+l2-1; i>=0; --i)
{
if(b[i]!=0)
{
y=0;
}
if(b[i]==0&&y)
{
continue;
}
cout<<b[i]; 
}
if(y) cout<<'0';
return 0;
}

我也不会


by 越学越掂 @ 2018-07-06 11:08:46

@汪佳凝 佳凝真逗


by 初音ミク_Miku @ 2018-07-06 12:25:03

what


by mabangjie @ 2018-07-17 10:26:21

#include<bits/stdc++.h>
using namespace std;
char a[9999],b[9999];
int  n[3000],m[3000],S[3000];
int  main()
{
    int w=0,k=0;
    cin>>a>>b;
    int lena=strlen(a);
    int lenb=strlen(b);
    for(int i=0;i<lena;i++)
       n[i]=a[la-i-1]-'0';
    for(int i=0;i<lenb;i++)
       m[i]=b[lb-i-1]-'0';
    for(int i=0;i<lena;i++)
     for(int j=0;j<lenb;j++)
     {
        S[i+j]+=n[i]*m[j];
        if(S[i+j]!=0)
          w=i+j;
     }
    for(int i=0;i<=w+5;i++)
    {
       S[i+1]+=S[i]/10;
       S[i]=s[i]%10;
       if(S[i]!=0)
         k=i;
    }
    for(int i=k;i>=0;i--)
       cout<<S[i];
    return 0;
}

by mabangjie @ 2018-07-17 10:28:36

sorry

中间的la和lb写错了

要改成lena,lenb


by mabangjie @ 2018-07-17 10:30:01

中间的s[i]=s[i]%10必须简化

s[i]%=10


|