#CS40305. 阅读程序3-枚举算法5
阅读程序3-枚举算法5
阅读程序
注意:切勿用电脑直接运行代码得出答案,请用大脑+笔+纸运行代码答题,否则是在浪费你的时间。
第3节:枚举算法
第5题【NOIP】2015
#include <iostream>
#include <string>
using namespace std;
int main() {
int len, maxlen;
string s, ss;
7 maxlen = 0;
do {
cin >> ss;
len = ss.length();
if (ss[0] == '#')break;
12 if (len > maxlen) {
s = ss;
maxlen = len;
}
} while (true);
cout << s << endl;
return 0;
}
●判断题
(1)输出可以包含#。
{{ select(5-1) }}
- 对
- 错
(2)如果去掉第7行的初始化,程序可能得不到正确答案。
{{ select(5-2) }}
- 对
- 错
(8)输出一定有字符
{{ select(5-3) }}
- 对
- 错
(4)如果把第12行的>改为>=,程序结果不会改变。
{{ select(5-4) }}
- 对
- 错
●选择题
(5)程序的时间复杂度级别为()
{{ select(5-5) }}
- 线性
- 对数
- 常数
- 平方
(6)输人I am a citizen of China #
,输出( )。
{{ select(5-6) }}
- am
- a
- citizen
- China
相关
在以下作业中: