Facile 0 risolte 0% di accettazione

Count Words

Count the words in a sentence.

A 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.

Vincoli

0 ≤ length ≤ 10,000

Esempi

Esempio 1
Input:
text = "Learn to code today"

Output atteso:
expected = 4
Input:
std::string text = "Learn to code today";

Output atteso:
long long expected = 4;
Input:
string text = "Learn to code today";

Output atteso:
long expected = 4;

Spiegazione

Four words separated by spaces: 4.

Esempio 2
Input:
text = "   "

Output atteso:
expected = 0
Input:
std::string text = "   ";

Output atteso:
long long expected = 0;
Input:
string text = "   ";

Output atteso:
long expected = 0;

Spiegazione

Only spaces, so there are no words: 0.

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.