簡単 0件解決済み 正答率0%

Title Case

Capitalize the first letter of every word.

このチャレンジで学べること

  • Change the case of single characters
  • Process each word of a sentence
  • Join words back into one string

問題

翻訳を表示

Convert text to title case: the first letter of every word becomes uppercase and the remaining letters lowercase. Words are separated by single spaces.

Implement title_case(text).

Input

text: Lowercase or mixed-case words separated by single spaces.

Output

Return the title-cased text.

制約

0 ≤ length ≤ 10,000 (letters and spaces)

例

例 1
入力:
text = "hello world"

期待される出力:
expected = "Hello World"
入力:
std::string text = "hello world";

期待される出力:
std::string expected = "Hello World";
入力:
string text = "hello world";

期待される出力:
string expected = "Hello World";

解説

"hello" → "Hello" and "world" → "World".

例 2
入力:
text = "tHE qUICK fox"

期待される出力:
expected = "The Quick Fox"
入力:
std::string text = "tHE qUICK fox";

期待される出力:
std::string expected = "The Quick Fox";
入力:
string text = "tHE qUICK fox";

期待される出力:
string expected = "The Quick Fox";

解説

Remaining letters become lowercase: "The Quick Fox".

解き方のヒント

まずは自分で考えてから、ヒントを 1 つずつ開いてみましょう。

ヒント 1

Split the text into words and treat each word independently.

ヒント 2

Uppercase the first character and lowercase the rest, then join the words back with spaces.

ヒント 3

Watch for empty input so you do not try to access a missing first character.

目安の計算量

O(n) time, O(n) extra space

参考資料

この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。