Dreamliu6 @ 2023-11-01 16:34:20
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
char a[10000] = {0}, b[10000] = {0}, * p = a, * q = b;
long long x = 0, y = 0,c = 0,d = 0,m,n;
gets_s(a);
gets_s(b);
x = strlen(a);
y = strlen(b);
m = x; n = y;
for (long long i = 0; i < x; ++i) {
c += pow(10, m - 1)*(a[i] - '0');
--m;
}
for (long long j = 0; j < y; ++j) {
d += pow(10, n - 1)*(b[j] - '0');
--n;
}
printf("%lld",c*d);
return 0;
}
by Hilte @ 2023-11-01 16:39:56
@Dreamliu6 gets_s?
by Argvchs @ 2023-11-01 16:48:20
@Dreamliu6
每个非负整数不超过
10^{2000} 。
by Dreamliu6 @ 2023-11-01 18:37:19
@Hilte 我提交时没加_s
by Dreamliu6 @ 2023-11-01 18:38:19
@Argvchs 所以是数组小了吗
by kkk02 @ 2023-11-01 21:34:08
#include<bits/stdc++.h>
using namespace std;
const int maxn=10000;
int main(){
char numa[maxn],numb[maxn];
int a[maxn],b[maxn],c[maxn];
scanf("%s",numa);
scanf("%s",numb);
int la=strlen(numa);
int lb=strlen(numb);
memset(c,0,sizeof(c));
for(int i=0;i<la;i++) a[la-i]=numa[i]-'0';
for(int i=0;i<lb;i++) b[lb-i]=numb[i]-'0';
for(int i=1;i<=la;i++){
for(int j=1;j<=lb;j++)c[i+j-1]+=a[i]*b[j];
}
int lc=la+lb;
for(int i=1;i<=lc;i++){
c[i+1]+=c[i]/10;
c[i]%=10;
}
while(c[lc]==0&&lc>1)lc--;
for(int i=lc;i>=1;i--)cout<<c[i];
return 0;
}
算了,直接上ac代码,自己看。
by xiaoshumiao @ 2023-11-20 12:20:39
@Dreamliu6 不是数组开小了,而是最后结果