xprintiny @ 2024-07-23 00:56:47
服了服了,写了两个晚上,就是不通过,反复测试修改,才发现,是getchar的问题!!!但是不知道啥原因
#include<bits/stdc++.h>
using namespace std;
int a[10001]={0};
int b[10001]={0};
int ans[10001]={0};
int main() {
char c;
int la = 0, lb = 0;
while ((c = getchar()) != '\n') {
a[la++] = c - '0';
}
while ((c = getchar()) != '\n') {
b[lb++] = c - '0';
}
// 判断0
if (la == 1 && a[0] == 0 || lb == 1 && b[0] == 0) {
cout<<0;
return 0;
}
//运算
int index,i,ce;
for(index = 0; la > index; index++){
ce=0;
for(i = 0; lb > i; i++){
ans[index+i] += a[la-index-1] * b[lb-i-1] + ce;
if(ans[index+i] > 9){
ce = ans[index+i]/10;
ans[index+i] = ans[index+i]%10;
}else ce = 0;
}
ans[index+i] += ce;
}
//输出
int j=index+i;
while(ans[j]==0 && j>0) j--;
for(; j>=0; j--){
cout<<ans[j];
}
return 0;
}
by LiujunjiaNC @ 2024-07-23 07:39:17
#include<bits/stdc++.h>
using namespace std;
int a[10001]={0};
int b[10001]={0};
int ans[10001]={0};
int main() {
char c;
int la = 0, lb = 0;
while ((c = getchar()) != '\n') {
if(c=='\r')continue;
a[la++] = c - '0';
}
while ((c = getchar()) != '\n') {
if(c=='\r')continue;
b[lb++] = c - '0';
}
// 判断0
if (la == 1 && a[0] == 0 || lb == 1 && b[0] == 0) {
cout<<0;
return 0;
}
//运算
int index,i,ce;
for(index = 0; la > index; index++){
ce=0;
for(i = 0; lb > i; i++){
ans[index+i] += a[la-index-1] * b[lb-i-1] + ce;
if(ans[index+i] > 9){
ce = ans[index+i]/10;
ans[index+i] = ans[index+i]%10;
}else ce = 0;
}
ans[index+i] += ce;
}
//输出
int j=index+i;
while(ans[j]==0 && j>0) j--;
for(; j>=0; j--){
cout<<ans[j];
}
return 0;
}
by LiujunjiaNC @ 2024-07-23 07:40:55
@xprintiny 这是出题人的锅测试点配置要求
by LiujunjiaNC @ 2024-07-23 07:42:38
@xprintiny 数据是CR+LF (\r\n) 作为换行符