Problema
Ver traduçãoA word is a run of non-space characters. Count the words in text; there may be extra spaces at the start, end or between words.
Implement count_words(text).
Input
text: The text to count.
Output
Return the number of words.
Restrições
0 ≤ length ≤ 10,000
Exemplos
Exemplo 1
Entrada:
text = "Learn to code today"
Saída esperada:
expected = 4
Entrada:
std::string text = "Learn to code today";
Saída esperada:
long long expected = 4;
Entrada:
string text = "Learn to code today";
Saída esperada:
long expected = 4;
Explicação
Four words separated by spaces: 4.
Exemplo 2
Entrada:
text = " "
Saída esperada:
expected = 0
Entrada:
std::string text = " ";
Saída esperada:
long long expected = 0;
Entrada:
string text = " ";
Saída esperada:
long expected = 0;
Explicação
Only spaces, so there are no words: 0.
Referências
Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.