首页 > 试题广场 >

#include #include...

[填空题]
#include<iostream>
#include<string>
using namespace std;
int main(void) {
    string str;
    int i;
    int count;
    count = 0;
    getline(cin, str);
    for (i = 0; i < str.length( ); i++) {
        if (str[i] >= 'a' && str[i] <= 'z')
            count++;
    }
    cout << "It has " << count << " lowercases" << endl;
    return 0;
}

输入:NOI2016 will be held in Mian Yang.
输出:1
输出暴露了程序目的,数小写字母的个数。
注意 getline读取字符串,可以有效的处理“空格”
发表于 2019-09-27 17:20:58 回复(0)