// Arup Guha
// 3/30/2012
// Solution COP 3223 Exam Question #4: Darts
#include <stdio.h>

int main() {

    // Open the input file.
    FILE* ifp = fopen("darts.txt", "r");

    // Initialize the darts array.
    int i;
    int darts[21];
    for (i=0; i<21; i++)
        darts[i] = 0;

    // Read in the number of dart throws.
    int numdarts;
    fscanf(ifp, "%d", &numdarts);

    int sum = 0, min=21, max=-1;

    // Go through each throw.
    for (i=0; i<numdarts; i++) {

        int number;
        fscanf(ifp, "%d", &number);

        // Adjust the frequency of this number.         	
        darts[number]++;

        // Keep track of the running score.
        sum += number;

        // Update the min and max throw, if necessary.
        if (number < min)
            min = number;
        if (number > max)
            max = number;
    }

    // Print out the statistics.
    printf("The minimum dart throw was %d.\n", min);
    printf("The maximum dart throw was %d.\n", max);
    printf("The average dart throw was %.2lf.\n", (double)sum/numdarts);

    // Print the frequency chart. Only positive rows.
    printf("Value\tNumber of Darts\n");
    for (i=0; i<21; i++)
        if (darts[i] > 0)
            printf("%d\t%d\n", i, darts[i]);

    fclose(ifp);

    return 0;
}
