题解 | 首字母大写

#include <cctype>
#include <iostream>
#include <vector>
#include <string>


using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::string;

int main() {
    string line;    // 按行处理
    while (std::getline(cin, line)) {
        bool flag = true;  // 标记本字符前一个字符是否是空白字符
        for (auto& elem : line) {
            if (flag) {
                if (elem >= 'a' && elem <= 'z') {
                    elem -= 32; // 小写改大写
                }
            }
            if (isspace(elem))
                flag = true;
            else 
                flag = false;
        }
        cout << line << endl;
    }

    return 0;
}

全部评论

相关推荐

迷茫的大四🐶:你这个拿去投央国企吧,投私企包过不了的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务