Легко Решено: 0 Процент решений: 0%

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.

Ограничения

0 ≤ length ≤ 10,000

Примеры

Пример 1
Ввод:
text = "Learn to code today"

Ожидаемый вывод:
expected = 4
Ввод:
std::string text = "Learn to code today";

Ожидаемый вывод:
long long expected = 4;
Ввод:
string text = "Learn to code today";

Ожидаемый вывод:
long expected = 4;

Пояснение

Four words separated by spaces: 4.

Пример 2
Ввод:
text = "   "

Ожидаемый вывод:
expected = 0
Ввод:
std::string text = "   ";

Ожидаемый вывод:
long long expected = 0;
Ввод:
string text = "   ";

Ожидаемый вывод:
long expected = 0;

Пояснение

Only spaces, so there are no words: 0.

Ссылки

Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.

Учитесь у других

Решения сообщества

Пока нет опубликованных решений. Решите задание, чтобы поделиться первым.