A triage tool skims a free-text bug report and needs two counts.
a-z, A-Z). Any non-letter character (digit, space, punctuation, newline) breaks a word. So x9y contains the two words x and y, and 42 contains no words.., !, ?. A sentence is a maximal run of one or more consecutive terminator characters; each such run counts as exactly one sentence. So Wait... really?! ends with two sentences (the run ... and the run ?!). Text with no terminator character contains zero sentences.Report the word count and the sentence count.
The entire input is the text (it may span several lines).
A single line with two space-separated integers: the word count and the sentence count.
Example 1
Input
Hello world. How are you?
Expected
5 2
Explanation
Words: Hello, world, How, are, you = 5. Terminator runs: the single dot and the single question mark = 2 sentences. Output is 5 2.
Example 2
Input
abc123def
Expected
2 0
Explanation
The digits split the letters into two words abc and def. There are no terminators, so 0 sentences. Output is 2 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →