#CS40307. 阅读程序3-枚举算法7

阅读程序3-枚举算法7

阅读程序

注意:切勿用电脑直接运行代码得出答案,请用大脑+笔+纸运行代码答题,否则是在浪费你的时间。

第3节:枚举算法

第7题【NOIP】2016

#include <iostream>
using namespace std;
int main() {
	int Max, Min, sum, count = 0;
	int tmp;
	cin >> tmp;
	if (tmp == 0)
		return 0;
	Max = Min = sum = tmp;
	count++;
	while (tmp != 0) {
		cin >> tmp;
		if (tmp != 0) {
			sum += tmp;
			count++;
			if (tmp > Max)
				Max = tmp;
			if (tmp < Min)
				Min = tmp;
		}
	}
22	cout << Max << "," << Min << "," << sum / count << endl;
	return 0;
}

●判断题

(1)程序一定会输出3个正个整数并用逗号隔开

{{ select(7-1) }}

(2)若把Max,Min,sum的数据类型改为double.则输出结果会改变。

{{ select(7-2) }}

(3)输入1 2 0 3 4 5 0 7 0时,count值最终为8.

{{ select(7-3) }}

(4)程序的时间复杂度瓶颈在于第22行计算答案过程。

{{ select(7-4) }}

●选择题

(5)程序的时间复杂度为()

{{ select(7-5) }}

  • O(1)
  • O(count)
  • O(\infty)
  • O(tmp)

(6)若输入为1 9 2 8 3 7 4 6 0 5,则会输出()。

{{ select(7-6) }}

  • 9,1,5
  • 9,1,6
  • 9,1,7
  • 9,1,8