谁能解读一下这个道题如何读入输出的
  • 板块学术版
  • 楼主rqf20071011
  • 当前回复10
  • 已保存回复10
  • 发布时间2023/8/10 15:21
  • 上次更新2023/11/3 04:43:13
查看原帖
谁能解读一下这个道题如何读入输出的
1056698
rqf20071011楼主2023/8/10 15:21
输入一些整数,求出它们的最小值、最大值和平均值(保留3位小数)。
输入包含多组数据,每组数据第一行是整数个数n,第二行是n个整数。n=0为输入结束标记,程序应当忽略这组数据。相邻两组数据之间应输出一个空行。
样例输入:
8
2 8 3 5 1 7 3 6
4
-4 6 10 0
0
样例输出:
Case 1:1 8 4.375

Case 2: -4 10 3.000

给出的代码(有BUG)如下:

#include <cstdio>
#define INF 1000000000000000000
using namespace std;
int main()
	int x,n=0,kase=0;
	while(scanf("%d",&n)==1&&n){
		int s=0,min=INF,max=-INF;
		for(int i=0;i<n;i++){
			scanf("%d",&x);
			s+=x;
			if(x<min)min=x;
			if(x>max)max=x;
		}
		if(kase) printf("\n");
		printf("Case %d: %d %d %.3lf\n",++kase,min,max,(double)s/n);
	}
	return 0;
}
2023/8/10 15:21
加载中...