← Back to STL Containers
Question 549
Digit Histogram from Input
Digit Histogram from Input
Write 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 anarray<int, 10>where indexdholds the count for digitd. 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 — 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.