Alle Herausforderungen
Einfach 0 gelöst 0% Erfolgsquote

Initials From a Name

Build uppercase initials from a full name.

Das lernst du

  • Split a name into words
  • Take the first letter of each word
  • Join and uppercase the result

Problem

Übersetzung anzeigen

Take the first letter of each word in full_name, uppercase it, and join the letters. Words are separated by one or more spaces.

Implement initials(full_name).

Input

full_name: A name made of letters and spaces.

Output

Return the initials, for example "ADL".

Einschränkungen

1 ≤ length of full_name ≤ 200; it contains at least one letter

Beispiele

Beispiel 1
Eingabe:
full_name = "Ada Lovelace"

Erwartete Ausgabe:
expected = "AL"
Eingabe:
std::string full_name = "Ada Lovelace";

Erwartete Ausgabe:
std::string expected = "AL";
Eingabe:
string full_name = "Ada Lovelace";

Erwartete Ausgabe:
string expected = "AL";

Erläuterung

A from Ada and L from Lovelace: "AL".

Beispiel 2
Eingabe:
full_name = "grace  brewster  hopper"

Erwartete Ausgabe:
expected = "GBH"
Eingabe:
std::string full_name = "grace  brewster  hopper";

Erwartete Ausgabe:
std::string expected = "GBH";
Eingabe:
string full_name = "grace  brewster  hopper";

Erwartete Ausgabe:
string expected = "GBH";

Erläuterung

Extra spaces don't matter; the initials are uppercased: "GBH".

So gehst du vor

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

Hinweis 1

Each word contributes exactly one character: its first letter.

Hinweis 2

Traverse the name while tracking when a new word starts after spaces.

Hinweis 3

Watch for multiple spaces in a row so you only take one initial per word.

Erwartete Komplexität

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

Referenzen

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

Von anderen lernen

Community-Lösungen

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