#C13493. Histogram Analysis and Operations

    ID: 43037 Type: Default 1000ms 256MiB

Histogram Analysis and Operations

Histogram Analysis and Operations

You are given a list of integers and several queries. Your task is to perform a series of operations on the histogram (multiset) of these numbers. Specifically, you need to:

  1. Compute the maximum value in the list. If the list is empty, output "None".
  2. Compute the minimum value in the list. If the list is empty, output "None".
  3. Compute the mean of the values in the list and print it as a floating-point number with one decimal (e.g., (3.0)). If the list is empty, output "None".
  4. For a given number of queries, determine the frequency (count) of a specific integer in the list. If the number does not exist in the list, output 0.
  5. Finally, print a bar chart representation of the histogram. For each distinct integer (in ascending order), print a line in the format:

( value: \ast\ast\ldots\ast )

where the number of asterisks corresponds to the frequency of that integer.

The input is read from standard input (stdin) and the output is written to standard output (stdout). Make sure your solution handles edge cases such as an empty list.

inputFormat

The input is given in the following format from stdin:

  • The first line contains an integer (N), the number of integers in the list.
  • The second line contains (N) space-separated integers.
  • The third line contains an integer (Q), the number of frequency queries.
  • The following (Q) lines each contain a single integer representing a query for which you must determine the frequency in the list.

For example:

10 1 2 2 3 3 3 4 4 4 4 3 3 1 5

outputFormat

The output should be written to stdout and must contain the following lines in order:

  1. The maximum value in the list (or "None" if the list is empty).
  2. The minimum value in the list (or "None" if the list is empty).
  3. The mean of the values (formatted to one decimal, or "None" if the list is empty).
  4. For each of the (Q) queries, a line outputting the frequency of the queried integer in the list.
  5. Finally, lines representing the histogram where for each unique integer (in ascending order) you print a line in the format: "value: ", where is a sequence of asterisks corresponding to the frequency of that value.

For example, the output corresponding to the sample input could be:

4 1 3.0 3 1 0 1: * 2: ** 3: *** 4: ****## sample

10
1 2 2 3 3 3 4 4 4 4
3
3
1
5
4

1 3.0 3 1 0 1: * 2: ** 3: *** 4: ****

</p>