समस्या
अनुवाद दिखाएँ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 के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।