line consists of lowercase English letters, digits, hyphens -, the marks !, ., , and spaces. Spaces (one or more in a row) split it into tokens.
A token is a well-formed word if all of the following hold:
- it contains no digits;
- it has at most one hyphen, and if there is one, it has a letter on each side ("a-b" is fine, "-ab" and "ab-" are not);
- it has at most one punctuation mark, and if there is one, it comes last ("ok," and "!" are fine, "o!k" and "a.," are not).
Return the number of well-formed words in the line.line="well-known facts, x2 ok!" → 3
"well-known", "facts," and "ok!" are well formed, while "x2" contains a digit. The answer is 3.
line="-up mid- a-b-c .. !" → 1
In "-up" and "mid-" the hyphen sits at an edge, "a-b-c" has two hyphens, ".." has two punctuation marks. Only "!" qualifies, so the answer is 1.
line="go. go, go!" → 3
line="well-known facts, x2 ok!"
3
Run checks the first 3 tests in your browser. Submit checks all 323 tests on the server, hidden ones included.