Histogram
InterviewTime limit2sMemory limit1024 MB
Count occurrences of each non-whitespace character in a text and print a vertical histogram of # bars sorted by character code.
- Level
Medium5 of 10
- Topics
- Implementation, Array, Sorting, Simulation
- Solved
- No attempts yet
Problem
Vovochka is breaking into the Pentagon's security system. To do this, he needs to find out which characters appear most often in the secret encrypted messages. To study the characters more easily, Vovochka wants a graphical representation of how often each character occurs. So he wants to build a histogram of the character counts in a message. A histogram is a chart in which every character that occurs in the message at least once corresponds to a bar whose height is proportional to the number of times that character occurs in the message.
Input
The input file contains the encrypted text of the message. It consists of uppercase and lowercase Latin letters, digits, punctuation marks (<<.>>, <<!>>, <<?>>, <<:>>, <<->>, <<,>>, <<;>>, <<(>>, <<)>>), spaces, and newlines. The size of the input file does not exceed bytes. The text contains at least one non-whitespace character. Every line of the input file is at most 200 characters long.
Output
For every character other than spaces and newlines, output a bar made of # characters. Its length must equal the number of occurrences of in the text. Below each bar, write the character it corresponds to. Format the histogram so that the bottom ends of the bars lie on the same row, and the first row and the first column are nonempty. Do not separate the bars from one another. Sort the bars in increasing order of character code.