B
B
bunnyyy2020-10-14 19:39:12
JavaScript
bunnyyy, 2020-10-14 19:39:12

How to solve this problem using an array of chars?

Count the number of words in the input string (a word is a sequence of characters starting with a letter).

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexey Ukolov, 2016-02-28
@enot_enotov

The error is due to the fact that internally the function f calls itself recursively. At the time of the call, the variable f is already null , so it cannot be called as a function.
You don't have recursion, so there is no error.
It’s better not to think about memory cells when working with js, you will only get confused.

D
Dark Hole, 2016-02-28
@abyrkov

The author calls f in
f when calling gf - null - then an error
If you write without calling f - there will be no error)
Fuck this author

T
Timur Pokrovsky, 2020-10-14
@bunnyyy

1. You cannot declare an ordinary array without knowing the number of elements in advance. You must use a vector/dynamic array/string type.
2. std::isalpha(std::locale)

W
Wataru, 2020-10-14
@wataru

Well... read one character at a time. We can consider, for example, the beginning of words. What is the beginning of a word? It is a character-letter preceded by a non-letter. All you have to store is whether the previous character was a letter. If the previous one was not, but the current one is, then add 1 to the answer. You also need to carefully consider the case of a word at the very beginning (i.e. actually add 1 if the current one is a letter and position == 0 or the previous character is not a letter).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question