Problem
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.
Constraints
0 ≤ length ≤ 10,000
Examples
Example 1
Input:
text = "Learn to code today"
Expected output:
expected = 4
Input:
std::string text = "Learn to code today";
Expected output:
long long expected = 4;
Input:
string text = "Learn to code today";
Expected output:
long expected = 4;
Explanation
Four words separated by spaces: 4.
Example 2
Input:
text = " "
Expected output:
expected = 0
Input:
std::string text = " ";
Expected output:
long long expected = 0;
Input:
string text = " ";
Expected output:
long expected = 0;
Explanation
Only spaces, so there are no words: 0.
References
This challenge is adapted for CodeUtility. Follow the statement and constraints above.