Einfach 0 gelöst 0% Erfolgsquote

Title Case

Capitalize the first letter of every word.

Das lernst du

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

Problem

Übersetzung anzeigen

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.

Einschränkungen

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

Beispiele

Beispiel 1
Eingabe:
text = "hello world"

Erwartete Ausgabe:
expected = "Hello World"
Eingabe:
std::string text = "hello world";

Erwartete Ausgabe:
std::string expected = "Hello World";
Eingabe:
string text = "hello world";

Erwartete Ausgabe:
string expected = "Hello World";

Erläuterung

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

Beispiel 2
Eingabe:
text = "tHE qUICK fox"

Erwartete Ausgabe:
expected = "The Quick Fox"
Eingabe:
std::string text = "tHE qUICK fox";

Erwartete Ausgabe:
std::string expected = "The Quick Fox";
Eingabe:
string text = "tHE qUICK fox";

Erwartete Ausgabe:
string expected = "The Quick Fox";

Erläuterung

Remaining letters become lowercase: "The Quick Fox".

So gehst du vor

Versuch es zuerst allein und öffne dann einen Hinweis nach dem anderen.

Hinweis 1

Split the text into words and treat each word independently.

Hinweis 2

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

Hinweis 3

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

Erwartete Komplexität

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

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Die beste bestandene Lösung jedes Coders. Schnellere, sparsamere und besser bewertete Lösungen stehen weiter oben.

Noch keine bestandene Lösung. Löse sie und hol dir Platz eins.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.