C 无法清除测试用例:我应该为此编写代码:
苹果和橘子的问题 12个测试用例中只有3个被清除。从几小时后就想不出别的了 样本输入0 样本输出0 问题: 密码C 无法清除测试用例:我应该为此编写代码:,c,testcase,C,Testcase,苹果和橘子的问题 12个测试用例中只有3个被清除。从几小时后就想不出别的了 样本输入0 样本输出0 问题: 密码 intmain(){ int-s; int t; scanf(“%d%d”、&s和&t); INTA; int b; scanf(“%d%d”、&a和&b); int m; int n; scanf(“%d%d”,&m,&n); int*apple=malloc(sizeof(int)*m); for(int apple_i=0;apple_i=orange+b) noo++; }
intmain(){
int-s;
int t;
scanf(“%d%d”、&s和&t);
INTA;
int b;
scanf(“%d%d”、&a和&b);
int m;
int n;
scanf(“%d%d”,&m,&n);
int*apple=malloc(sizeof(int)*m);
for(int apple_i=0;apple_i f(d>=s&&d=s&&d代码中的错误非常小。您已经切换了橙子和苹果的输出。更改
printf("%d\n", fellor);
printf("%d\n", fellap);
到
我不认为需要将所有值读取到数组中。您可以简单地遍历输入,同时进行计算。下面是一个通过所有测试用例的示例:
int main(){
int s;
int t;
scanf("%d %d",&s,&t);
int a;
int b;
scanf("%d %d",&a,&b);
int m;
int n;
scanf("%d %d",&m,&n);
int noApples=0;
int noOranges=0;
for(int apple_i = 0; apple_i < m; apple_i++){
int apple;
scanf("%d",&apple);
if (apple+a >= s && t >= apple+a)
noApples++;
}
for(int orange_i = 0; orange_i < n; orange_i++){
int orange;
scanf("%d",&orange);
if (orange+b >= s && t >= orange+b)
noOranges++;
}
printf("%d\n%d\n", noApples, noOranges);
return 0;
}
通过所有测试用例的工作代码:
int main(){
int s;
int t;
scanf("%d %d",&s,&t);
int a;
int b;
scanf("%d %d",&a,&b);
int m;
int n;
scanf("%d %d",&m,&n);
int noApples=0;
int noOranges=0;
for(int apple_i = 0; apple_i < m; apple_i++){
int apple;
scanf("%d",&apple);
if (apple+a >= s && t >= apple+a)
noApples++;
}
for(int orange_i = 0; orange_i < n; orange_i++){
int orange;
scanf("%d",&orange);
if (orange+b >= s && t >= orange+b)
noOranges++;
}
printf("%d\n%d\n", noApples, noOranges);
return 0;
}
intmain(){
int-s;
int t;
scanf(“%d%d”、&s和&t);
INTA;
int b;
scanf(“%d%d”、&a和&b);
int m;
int n;
scanf(“%d%d”,&m,&n);
int noApples=0;
int=0;
for(int apple_i=0;apple_i=s&t>=苹果+a)
noApples++;
}
for(int橙色i=0;橙色i=s&t>=orange+b)
noo++;
}
printf(“%d\n%d\n”,无应用程序,无范围);
返回0;
}
Formatting/indentation:(为了清楚起见,您希望我们为您的参赛作品运行测试/调试循环?谢谢您,先生。您能告诉我为什么我的代码没有通过所有测试吗?正如我所说,您已经改变了printf:s的顺序
printf("%d\n", fellor);
printf("%d\n", fellap);
printf("%d\n", fellap);
printf("%d\n", fellor);
int main(){
int s;
int t;
scanf("%d %d",&s,&t);
int a;
int b;
scanf("%d %d",&a,&b);
int m;
int n;
scanf("%d %d",&m,&n);
int noApples=0;
int noOranges=0;
for(int apple_i = 0; apple_i < m; apple_i++){
int apple;
scanf("%d",&apple);
if (apple+a >= s && t >= apple+a)
noApples++;
}
for(int orange_i = 0; orange_i < n; orange_i++){
int orange;
scanf("%d",&orange);
if (orange+b >= s && t >= orange+b)
noOranges++;
}
printf("%d\n%d\n", noApples, noOranges);
return 0;
}