Poombom @ 2023-06-21 19:46:57
肯定不是因为我太逊了
代码如下
#include<iostream>
#include<cstring>
using namespace std;
char a[5000],b[5000];
int x[5000],y[5000],c[5000],d;
int main( )
{
int i;
cin>>a>>b;
x[0]=strlen(a);
y[0]=strlen(b);
for(int i=1;i<=a[0];i++)x[i]=a[x[0]-i]-'0';
for(int i=1;i<=b[0];i++)y[i]=b[y[0]-i]-'0';
for(i=1;i<=x[0];i++)
{
for(int j=1;j<=y[0];j++)
{
c[i+j-1]=x[i]*y[j];
}
}
for(int i=1;i<x[0]+y[0];i++)
{
if(c[i]>=10)
{
c[i]=c[i]%10;
c[i+1]+=c[i]/10;
}
}
d=x[0]+y[0];
while(c[d]==0&&d>1)d--;
for(int i=d;i>0;i--)
cout<<c[i];
return 0;
}
语言:c++14
by Li_mz__ @ 2023-06-21 19:52:38
@Poombom 说明/提示 每个非负整数不超过 10的2000次方
不开long long见祖宗
by Milthm @ 2023-06-21 19:52:56
@Poombom a[0]和b[0]没赋值呢吧
而且字符串这么读入是从0编号的
by Milthm @ 2023-06-21 19:53:25
@Li_mz__ 高精度要开long long ???
by Li_mz__ @ 2023-06-21 19:54:36
@songjiahao_
#include <bits/stdc++.h>
using namespace std;
int main(){
string s1,s2;
long long x[2005] = {0},y[2005] = {0},sum[4005] = {0};
cin>>s1>>s2;
int l1 = s1.length();
int l2 = s2.length();
for(int i = 0;i < l1;i++){
x[l1 - 1 - i] = s1[i] - '0';
}
for(int i = 0;i < l2;i++){
y[l2 - 1 - i] = s2[i] - '0';
}
for(int i = 0;i < l1;i++){
for(int j = 0;j < l2;j++){
sum[i + j] += x[i] * y[j];
sum[i + j + 1] += sum[i + j] / 10;
sum[i + j] %= 10;
}
}
int l = l1 + l2;
while(sum[l] == 0 && l != 0){
l--;
}
for(int i = l;i >= 0;i--){
cout<<sum[i];
}
return 0;
}
by Milthm @ 2023-06-21 19:56:11
@Li_mz__ 额,你换成int也能过吧……
by Li_mz__ @ 2023-06-21 19:56:59
@songjiahao_ 我逝逝
by Li_mz__ @ 2023-06-21 19:57:32
@songjiahao_ 过了………………
by Poombom @ 2023-06-21 19:58:49
11行和14行为什么是11和12?
by zsh_haha @ 2023-06-21 20:01:27
@Poombom 解决高精最好办法,Python!
a=int(input())
b=int(input())
print(a*b)
by Poombom @ 2023-06-21 20:01:48
longlong 编译失败...................................................