_Proselyte_ @ 2023-10-01 10:16:15
#include<stdio.h>
int main()
{
int a,b,c,d,e,f,g,h,i,j,height;
int counter=0,num=0;
scanf("%d %d %d %d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
scanf("%d",&height);
int array[10]={a,b,c,d,e,f,g,h,i,j};
do
{
counter++;
if(array[counter-1]<=height+30)
num++;
}while(counter<11);
printf("%d",num);
return 0;
}
by AndrewX @ 2023-10-01 10:17:52
会用数组吗
by wanglexi @ 2023-10-01 10:32:47
没有输出时因为Runtime Error
了
第六行输入10个高度但打了11个%d
删除一个%d
scanf("%d %d %d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
另外,下面do-while
循环处,counter=10时通过while进入do,counter++变成11,还会另外判别一次array[10],但是苹果高度存在array[0~9]里,所以应该改为while(counter<10);
AC代码:
#include<stdio.h>
int main()
{
int a,b,c,d,e,f,g,h,i,j,height;
int counter=0,num=0;
scanf("%d %d %d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
scanf("%d",&height);
printf("%");
int array[10]={a,b,c,d,e,f,g,h,i,j};
do
{
counter++;
if(array[counter-1]<=height+30)
num++;
}while(counter<10);
printf("%d",num);
return 0;
}
by hexuchen @ 2023-10-01 10:33:42
@Proselyte scanf
写错了,一共要输入10个变量,然而你的scanf
的%d
却有11个
#include<stdio.h>
int main()
{
int a,b,c,d,e,f,g,h,i,j,height;
int counter=0,num=0;
scanf("%d %d %d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
scanf("%d",&height);
int array[11]={a,b,c,d,e,f,g,h,i,j};
do
{
counter++;
if(array[counter-1]<=height+30)
num++;
}while(counter<11);
printf("%d",num-1);
return 0;
}
by wanglexi @ 2023-10-01 10:33:47
第8行手残不小心多打了一行
by _Proselyte_ @ 2023-10-01 10:45:26
是多打了一个&d的问题,删了就过了233,感谢