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".
Restrições
1 ≤ length of full_name ≤ 200; it contains at least one letter
Exemplos
Entrada:
full_name = "Ada Lovelace"
Saída esperada:
expected = "AL"
Entrada:
std::string full_name = "Ada Lovelace";
Saída esperada:
std::string expected = "AL";
Entrada:
string full_name = "Ada Lovelace";
Saída esperada:
string expected = "AL";
Explicação
A from Ada and L from Lovelace: "AL".
Entrada:
full_name = "grace brewster hopper"
Saída esperada:
expected = "GBH"
Entrada:
std::string full_name = "grace brewster hopper";
Saída esperada:
std::string expected = "GBH";
Entrada:
string full_name = "grace brewster hopper";
Saída esperada:
string expected = "GBH";
Explicação
Extra spaces don't matter; the initials are uppercased: "GBH".
Como abordar
Tente sozinho primeiro e depois abra uma dica de cada vez.
Dica 1
Each word contributes exactly one character: its first letter.
Dica 2
Traverse the name while tracking when a new word starts after spaces.
Dica 3
Watch for multiple spaces in a row so you only take one initial per word.
Complexidade esperada
O(n) time, O(1) extra space
Referências
Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.