dida_0420 @ 2024-12-06 14:23:14
#include <math.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
char A[10086],B[10086];
int a[10086],b[10086],c[20086];
int main()
{
gets(A);
gets(B);
int n=strlen(A);
int m=strlen(B);
for(int i=1;i<=n;i++)
{
a[i]=A[n-i]-'0';
}
for(int i=1;i<=m;i++)
{
b[i]=B[m-i]-'0';
}
for(int i = 1;i <= m;i++){
for(int j = 1;j <= n;j++){
c[i+j-1] += (a[j])* (b[i]);
}
}
for(int i =1;i <n + m;i++){
if(c[i]>9)
{
c[i+1]+=c[i]/10;
c[i]%=10;
}
}
int len=m+n;
while(c[len]==0&&len>1)
len--;
for(int i=len;i>=1;i--)
{
printf("%d",c[i]);
}
return 0;
}
by Diary_Of_Young @ 2024-12-06 14:43:15
考虑python
a = int(input())
b = int(input())
print(a * b)
by WE_TRT @ 2024-12-06 15:53:45
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main(){
int len1,len2,c[2006]={0},d[2006]={0},e[5001]={0},i,j;
cin>>a>>b;
len1=a.size();
len2=b.size();
for(i=0;i<len1;i++){
c[i]=a[len1-i-1]-'0';
}
for(i=0;i<len2;i++){
d[i]=b[len2-i-1]-'0';
}
for(i=0;i<len1;i++){
for(j=0;j<len2;j++){
e[i+j]=e[i+j]+c[i]*d[j];
}
}
for(i=0;i<5001;i++){
e[i+1]+=e[i]/10;
e[i]%=10;
}
for(i=len1+len2-1;e[i]==0&&i>.0;i--);
for(;i>=0;i--){
cout<<e[i];
}
return 0;
}
by wuzebang2009 @ 2024-12-06 15:55:50
i<=m+n