Li_mz__ @ 2022-09-16 21:46:44
#include <bits/stdc++.h>
using namespace std;
int main(){
string s1,s2;
long long x[1005] = {0},y[1005] = {0},sum[2005] = {0};
cin>>s1>>s2;
long long l1 = s1.length();
long long l2 = s2.length();
for(long long i = 0;i < l1;i++){
x[l1 - 1 - i] = s1[i] - '0';
}
for(long long i = 0;i < l2;i++){
y[l2 - 1 - i] = s2[i] - '0';
}
for(long long i = 0;i < l1;i++){
for(long long j = 0;j < l2;j++){
sum[i + j] += x[i] * y[j];
sum[i + j + 1] += sum[i + j] / 10;
sum[i + j] %= 10;
}
}
long long l = l1 + l2;
while(sum[l] == 0 && l != 0){
l--;
}
for(long long i = l;i >= 0;i--){
cout<<sum[i];
}
return 0;
}
求大佬看看
by Li_mz__ @ 2022-09-17 21:32:39
@scp020
#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 scp020 @ 2022-09-17 21:34:11
@Li_mz__ 就是野指针
by Li_mz__ @ 2022-09-17 21:35:17
@scp020 谢谢(我可真屑,学了指针还忘了)
by scp020 @ 2022-09-17 21:36:04
@Li_mz__ 你可以把它理解为你访问到了一个没有用的地址,那里面不一定装了什么
by Li_mz__ @ 2022-09-17 21:37:32
@scp020 哦哦,谢谢
快溜,有大佬