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.
Restricciones
0 ≤ length ≤ 10,000 (letters and spaces)
Ejemplos
Entrada:
text = "hello world"
Salida esperada:
expected = "Hello World"
Entrada:
std::string text = "hello world";
Salida esperada:
std::string expected = "Hello World";
Entrada:
string text = "hello world";
Salida esperada:
string expected = "Hello World";
Explicación
"hello" → "Hello" and "world" → "World".
Entrada:
text = "tHE qUICK fox"
Salida esperada:
expected = "The Quick Fox"
Entrada:
std::string text = "tHE qUICK fox";
Salida esperada:
std::string expected = "The Quick Fox";
Entrada:
string text = "tHE qUICK fox";
Salida esperada:
string expected = "The Quick Fox";
Explicación
Remaining letters become lowercase: "The Quick Fox".
Cómo abordarlo
Inténtalo primero por tu cuenta y luego abre las pistas una a una.
Pista 1
Split the text into words and treat each word independently.
Pista 2
Uppercase the first character and lowercase the rest, then join the words back with spaces.
Pista 3
Watch for empty input so you do not try to access a missing first character.
Complejidad esperada
O(n) time, O(n) extra space
Referencias
Este reto está adaptado para CodeUtility. Sigue el enunciado y las restricciones indicadas arriba.