Digit Histogram from Input
hardQuestion 549Write a program that reads non-negative integers from standard input until the input ends. Count how many times each decimal digit 0 to 9 appears across all the numbers, using an array<int, 10> where index d holds the count for digit d. The number 0 itself contributes one digit 0.
Print one line for each digit whose count is greater than zero, in increasing digit order: the digit, a colon, a space, and the count. Digits that never appeared are not printed at all.
Example input: 12 13
The output for that input is shown in Expected Output.
Expected output
1: 2 2: 1 3: 1 0: 4 1: 1 2: 1 5: 1
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
STL Containersstd::array
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.