Problema
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.
Restrições
0 ≤ length ≤ 10,000 (letters and spaces)
Exemplos
Entrada:
text = "hello world"
Saída esperada:
expected = "Hello World"
Entrada:
std::string text = "hello world";
Saída esperada:
std::string expected = "Hello World";
Entrada:
string text = "hello world";
Saída esperada:
string expected = "Hello World";
Explicação
"hello" → "Hello" and "world" → "World".
Entrada:
text = "tHE qUICK fox"
Saída esperada:
expected = "The Quick Fox"
Entrada:
std::string text = "tHE qUICK fox";
Saída esperada:
std::string expected = "The Quick Fox";
Entrada:
string text = "tHE qUICK fox";
Saída esperada:
string expected = "The Quick Fox";
Explicação
Remaining letters become lowercase: "The Quick Fox".
Como abordar
Tente sozinho primeiro e depois abra uma dica de cada vez.
Dica 1
Split the text into words and treat each word independently.
Dica 2
Uppercase the first character and lowercase the rest, then join the words back with spaces.
Dica 3
Watch for empty input so you do not try to access a missing first character.
Complexidade esperada
O(n) time, O(n) extra space
Referências
Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.