Kodewick
开始学 →
小挑战←→0 / 60

书架标签

#021小挑战字符串循环约 6 分钟

图书角的书架标签上,书名每个词的第一个字母要大写。写 title_case(title):词和词之间是一个空格,每个词的开头变大写,别的字不变。空的就返回空的。

示例
title_case("the little prince")→'The Little Prince'
title_case("")→''
函数string title_case(string title)
main.cpp
#include <string>
#include <cctype>
using namespace std;

string title_case(string title) {
    for (int i = 0; i < title.size(); i++) {
        // 在这里写:是开头或者前一个是空格,就把 title[i] 变大写
    }
    return title;
}
Ctrl + Enter 也能运行
结果

写好了先点「运行」试试示例,没问题再点「提交」。