Tutte le sfide
Facile 2 risolte 100.0% di accettazione

Initials From a Name

Build uppercase initials from a full name.

Cosa imparerai

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

Problema

Mostra traduzione

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

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

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

La migliore soluzione superata di ogni programmatore. Le più veloci, leggere e meglio valutate stanno in alto.

# Programmatore Linguaggio Tempo Memoria Voto dell'IA Soluzione
1 RCRiccardo Corti Python 699 ms - 5/5 Vedi il codice
2 LMLaura Mahlow Python 717 ms - 5/5 Vedi il codice

Impara dagli altri

Soluzioni della community

Attenzione spoiler: 2 soluzioni complete sotto Prova prima a risolverla da solo. Puoi comunque sbirciare il codice degli altri sviluppatori e le revisioni dell'IA. Accedi e risolvi la sfida per partecipare alla discussione.