圖書角的書架標籤上,書名每個詞的第一個字母要大寫。寫 title_case(title):詞和詞之間是一個空格,每個詞的開頭變大寫,別的字不變。空的就返回空的。
title_case("the little prince")→'The Little Prince'title_case("")→''string title_case(string title)#include <string>
#include <cctype>
using namespace std;
string title_case(string title) {
for (int i = 0; i < title.size(); i++) {
// 在這裡寫:是開頭或者前一個是空格,就把 title[i] 變大寫
}
return title;
}
寫好了先點「執行」試試示例,沒問題再點「提交」。