#CS40501. 阅读程序5-递推与递归1

阅读程序5-递推与递归1

阅读程序

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

第5节:递推与递归

第1题【NOIP】2008

#include<iostream>
using namespace std;
void foo(int a, int b, int c)
{
	if(a > b) 
		foo(c, a, b);
	else
		cout<<a<<','<<b<<','<<c<<endl;
}
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	foo(a, b, c);
	return 0;
}

●判断题

(1)该程序只输出一行

{{ select(1-1) }}

  • 正确
  • 错误

(2)如果输入的三个数都相同,程序会运行错误。

{{ select(1-2) }}

  • 正确
  • 错误

(3)如果输入3 1 2,输出2,3,1.

{{ select(1-3) }}

  • 正确
  • 错误

(4)如果输入3 2 1.程序会超时

{{ select(1-4) }}

  • 正确
  • 错误

●选择题

(5)输入9108,输出为()。

{{ select(1-5) }}

  • 9,10,8
  • 9,8,10
  • 10,8,9
  • 8,9,10

(6)令n代表输入变量a、b,c的次数,则n=3该程序的时间复杂度为( )。

{{ select(1-6) }}

  • O(n)
  • O(logn)
  • O(logn)O(\sqrt{logn})
  • O(log(nn))O(log(n\sqrt{n}))