#CS40301. 阅读程序3-枚举算法1

阅读程序3-枚举算法1

阅读程序

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

第3节:枚举算法

第1题【NOIP】2013

#include <iostream>
#include <string>
using namespace std;
int main() {
	string str;
	cin>>str;
	int n=str.size();
8	bool isPlalindrome=true;
	for (int i = 0; i < n/2; i++) {
		if (str[i] != str[n-i-1]){
11			isPlalindrome = 0;
		}			
	}
	if (isPlalindrome)
		printf("Yes\n");
	else
		printf("No\n");
18	return 0;
}

●判断题

(1)如果去掉第18行,程序不能正常运行。

{{ select(1-1) }}

(2)如果去掉第8行的初始化,程序可能得不到正确答案。

{{ select(1-2) }}

(3)在11行下添加一行break;,程序运行结果不变

{{ select(1-3) }}

(4)如果输入abceecba,输出Yes。

{{ select(1-4) }}

●选择题

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

{{ select(1-5) }}

  • O(n)
  • O(logn)
  • O(nlogn)
  • O(n2n^2)

(6)输入abcdefghijklmnmlkjihgfedcba,输出为( )。

{{ select(1-6) }}

  • No
  • Yes
  • NO
  • YES