Fácil 0 resueltos 0% de aceptación

Title Case

Capitalize the first letter of every word.

Lo que aprenderás

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

Problema

Ver traducción

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

Ejemplo 1
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".

Ejemplo 2
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.

Aprende de otros

Soluciones de la comunidad

Aún no hay soluciones publicadas. Resuelve este reto para compartir la primera.