#CS40205. 阅读程序2-字符处理-05

阅读程序

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

第2节:字符处理

第5题【NOIP】2015

01 #include <iostream>
02 #include <string> 
03 using namespace std;
04 int main(){
05     string str;
06     int i;
07     int count;
08     count = 0;
09     getline( cin, str );
10     for ( i = 0; i < str.length(); i++ )
11         if ( str[i] >= 'a' && str[i] <= 'z' )
12             count++;
13     cout << "It has " << count << " lowercases" << endl; 
14     return 0;
15 }

●判断题

(1)第9行输入的字符串可以是任意字符,包括字母、数字、各类符号甚至中文汉字及符号

(2)执行完第10行循环后,count的值可能为0。

(3)若去掉11行,输出结果不变。

(4)若输入的字符串中各字符互不相同,则count不为0。

●选择题

(5)输入CSP2001,count的结果是()

(6)若字符串的长度为n,算法的时间复杂度是()。