qwert1234567890 @ 2022-07-14 22:44:21
#include<bits/stdc++.h>
using namespace std;
int main(){
char a1[100000],b1[100000];
int a[100000],b[100000],c[100000],lena,lenb,lenc,i,x;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
cin>>a1;
cin>>b1;
lena=strlen(a1);
lenb=strlen(b1);
for(i=1;i<=lena;i++){
a[lena-i+1]=a1[i-1]-48;
}
for(i=1;i<=lenb;i++){
b[lenb-i+1]=b1[i-1]-48;
}
x=0;
int cs;
for(int i=1;i<=lenb;i++){
x=0;
for(int j=1;j<=lena;j++){
cs=i+j-1;
c[cs]=c[cs]+a[j]*b[i]+x;
x=c[cs]/10;
c[cs]=c[cs]%10;
}
}
lenc=cs;
if(c[lenc]==0)
cout<<"0";
else
for(int i=lenc;i>=1;i--){
cout<<c[i];
}
cout<<endl;
return 0;
}
自己测过测试点4的数据,开头结尾几十个数都没问题,救救孩子吧
by WYX1210 @ 2022-07-18 11:55:53
# A*B Problem
#include<iostream>
#include<string>
using namespace std;
#define maxn 5010
int A[maxn],B[maxn],C[maxn];
int main(){
string a,b;
cin>>a>>b;
int lena=a.length(),lenb=b.length();
for(int i=lena-1;i>=0;i--)A[lena-i]=a[i]-'0';
for(int i=lenb-1;i>=0;i--)B[lenb-i]=b[i]-'0';
for(int i=1;i<=lena;i++){
for(int j=1;j<=lenb;j++){
C[i+j-1]+=A[i]*B[j];
}
}
int len=lena+lenb;
for(int i=1;i<=len;i++){C[i+1]+=C[i]/10;C[i]%=10;}
for(;!C[len];)len--;
for(int i=max(1,len);i>=1;i--)cout<<C[i];
return 0;
}
by ht20110603 @ 2022-08-01 10:23:38
@qwert1234567890 用python解
by ht20110603 @ 2022-08-01 10:25:06
@qwert1234567890
a = int(input())
b = int(input())
print(a * b)
by YuKeWang @ 2022-08-08 20:57:22
a*b!AC