pangfengliu / programmingtasks

programming tasks from my courses
67 stars 17 forks source link

Statistics #272

Open pangfengliu opened 9 years ago

pangfengliu commented 9 years ago

Task Description

Write a program to compute statistic information about grades. The first set of information we will compute is the histogram. That is, we will compute the number of grades that are in a specified range. We will be given a set of grades, like 100, 90, 95, 87, and 68. The grades are between 0 and 100 inclusively. Then we will be given a set of ranges, like 100 to 95, 94 to 91, 90 to 87, 86 to 80, and 79 to 0. These five ranges will be represented by four integers, 95, 91, 87, and 80. Then our program should produce the histogram 2, 0, 2, 0, 1.

Then we will calculate the mean, the variance, and the standard derivation of our grades. The mean is the average of our input grades. The variance is the expected value of the square of the difference between the input and the mean. The standard derivation is the square root of the variance. For example, in the previous example the average of 100, 90, 95, 87, and 68 is 88. Now consider the 100, the difference between 100 and 88 is 12, and the square of this difference is 144. Similarly the square is 4 for 90, 49 for 95, 1 for 87, and 400 for 68. The variance is therefore the average of 144, 4, 49, 1, and 400, which is 119.6. Finally the standard derivation is the square root of 119.6, and is about 10.936178. Note that in order to calculate these information accurately, we should use double numbers.

Limits

There will be no more than 1000 input grades and 20 ranges.

Input

The first line of the input is a positive integer n, the number of grades. The second line has the n grades. The third line has m, the number of separators for the ranges. The fourth line has the m separators given in decreasing order. All separators are between 1 to 100 inclusively. Note that this means there are m + 1 ranges.

Output

There are two lines in the output. The first line is the histogram of the m + 1 ranges. The second line shows the mean, the variance, the standard derivation of the input grades in sequence.

Sample input

5 100 90 95 87 68 4 95 91 87 80

Sample output

2 0 2 0 1 88.000000 119.600000 10.936178

Test Data

You can download the test data (which JudgeGirl uses) from here.

sinmaplewing commented 9 years ago

Added the test data.