Programming contests

Magas szintű programozási nyelvek 1, egyéni verseny, 2012. április 22.

April 22, 2012 10:15 AM – April 22, 2012 3:15 PM

Histogram Generation

Develop a program that, given a collection of quiz scores, generates a histogram showing the collection’s frequency distribution. Quiz scores will be in the range zero to twenty, inclusive.

Input Specification

The first line contains a positive integer n indicating how many collections are to be processed. Each collection is described on two or more lines, the first of which contains the number of quiz scores m (m > 0) in that collection. The remaining lines contain the quiz scores themselves, twenty scores per line up until the last one, which will have a number of scores equal to the remainder obtained when m is divided by 20.

Output Specification

For each collection of quiz scores, the program should generate a histogram indicating the frequency with which each of the values zero through twenty occurs in that collection.

The histogram’s form should be as in the sample output below. Specifically, the only quiz scores that should be mentioned explicitly in the histogram are those between the minimum and maximum scores recorded, inclusive. (For the first example below, this range is ten through nineteen.) Be sure to fill all the white space occupied by the histogram with blanks, also at the end of each line so that all of them have the same length.

The number of lines generated for a histogram should be exactly k + 3, where k is the maximum number of occurrences of any of the quiz scores. This accounts for there being k asterisks in the tallest column, one line for the scale (containing dashes and plus signs), one line containing the quiz scores, and a blank line to separate one histogram from the next.

Sample Input

  1. 2
  2. 22
  3. 10 12 16 12 10 19 19 19 12 14 13 14 14 16 17 14 15 13 18 15
  4. 15 17
  5. 5
  6. 20 4 12 12 17
download as text file

Output for Sample Input

  1.              *               
  2.        *     *  *           *
  3.  *     *  *  *  *  *  *     *
  4.  *     *  *  *  *  *  *  *  *
  5. -+--+--+--+--+--+--+--+--+--+
  6. 10 11 12 13 14 15 16 17 18 19
  7.                          *                        
  8.  *                       *              *        *
  9. -+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
  10.  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019