Problema
Replace every space in text with a dash -, and convert all letters to lowercase.
Implement slugify_spaces(text).
Input
text: The text to convert.
Output
Return the converted text.
Vincoli
0 ≤ length of text ≤ 10,000
Esempi
Input:
text = "Hello World"
Output atteso:
expected = "hello-world"
Input:
std::string text = "Hello World";
Output atteso:
std::string expected = "hello-world";
Input:
string text = "Hello World";
Output atteso:
string expected = "hello-world";
Spiegazione
The space becomes a dash and letters are lowercased: "hello-world".
Input:
text = "Learn To Code"
Output atteso:
expected = "learn--to-code"
Input:
std::string text = "Learn To Code";
Output atteso:
std::string expected = "learn--to-code";
Input:
string text = "Learn To Code";
Output atteso:
string expected = "learn--to-code";
Spiegazione
Each space becomes its own dash: "learn--to-code".
Come affrontarlo
Prova prima da solo, poi apri un suggerimento alla volta.
Suggerimento 1
Trasforma l’intera stringa applicando sia la conversione in minuscolo sia la sostituzione degli spazi.
Suggerimento 2
Una singola passata può costruire il risultato gestendo ogni carattere.
Suggerimento 3
Fai attenzione a non modificare i caratteri non alfabetici, tranne gli spazi.
Complessità attesa
tempo O(n), spazio aggiuntivo O(n)
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.