The receiving dock at a regional warehouse logs one manifest per truck. Each manifest is a raw block of text listing the item codes carried on that truck, separated by ordinary whitespace (spaces, tabs, or newlines); spacing can be irregular, there can be blank lines, and the manifest is never preceded by a count of how many codes it holds. Given an entire manifest, report exactly how many item codes it lists.
The entire standard input is the manifest: zero or more whitespace-separated tokens (item codes) spread across one or more lines in any arrangement. Extra blank lines and runs of repeated whitespace are allowed and act only as separators. The input may be completely empty.
A single integer: the number of tokens present in the manifest.
0 <= number of tokens <= 1000001 to 20 printable, non-whitespace charactersExample 1
Input
A1 B2 C3
Expected
3
Explanation
The manifest lists three item codes -- A1, B2, and C3 -- separated by single spaces, so the tally is 3.
Example 2
Input
X Y Z W
Expected
4
Explanation
Each item code sits on its own line. Newlines are whitespace just like spaces, so this is still four separate tokens (X, Y, Z, W), giving a tally of 4.
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 →