This page is still under construction.

Parts of this page are still being built. What you see may change.

Histogram

Interview

Time limit2sMemory limit1024 MB

Summary
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 10410^4 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 cc other than spaces and newlines, output a bar made of # characters. Its length must equal the number of occurrences of cc 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.

Examples2

  1. Example 1

    Input
    Hello, world!
    
    Expected output
         #   
         ##  
    #########
    !,Hdelorw
    
  2. Example 2

    Input
    Twas brillig, and the slithy toves
    Did gyre and gimble in the wabe;
    All mimsy were the borogoves,
    And the mome raths outgrabe.
    
    Expected output
             #              
             #              
             #              
             #              
             #              
             #         #    
             #  #      #    
          #  # ###  ####    
          ## ###### ####    
          ##############    
          ##############  ##
    #  #  ############## ###
    ########################
    ,.;ADTabdeghilmnorstuvwy