Problema
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".
Vincoli
1 ≤ length of full_name ≤ 200; it contains at least one letter
Esempi
Input:
full_name = "Ada Lovelace"
Output atteso:
expected = "AL"
Input:
std::string full_name = "Ada Lovelace";
Output atteso:
std::string expected = "AL";
Input:
string full_name = "Ada Lovelace";
Output atteso:
string expected = "AL";
Spiegazione
A from Ada and L from Lovelace: "AL".
Input:
full_name = "grace brewster hopper"
Output atteso:
expected = "GBH"
Input:
std::string full_name = "grace brewster hopper";
Output atteso:
std::string expected = "GBH";
Input:
string full_name = "grace brewster hopper";
Output atteso:
string expected = "GBH";
Spiegazione
Extra spaces don't matter; the initials are uppercased: "GBH".
Come affrontarlo
Prova prima da solo, poi apri un suggerimento alla volta.
Suggerimento 1
Each word contributes exactly one character: its first letter.
Suggerimento 2
Traverse the name while tracking when a new word starts after spaces.
Suggerimento 3
Watch for multiple spaces in a row so you only take one initial per word.
Complessità attesa
O(n) time, O(1) extra space
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.