#include <stdio.h>
#include <math.h>

/* 最大数据项数和直方图的最大高度 */
enum { NUM = 200, HISTOHIGH = 60 };

double scores[NUM];

int readscores(int lim, double tb[]); /*输入不超过lim个数据到tb，返回项数*/
void statistics(int num, double tb[]); /*统计tb里的num个数据项*/
void histogram(int num, double tb[], int high); /*做最高为high的直方图*/

int main() {
    int n;
    n = readscores(NUM, scores);
    statistics(n, scores);
    histogram(n, scores, HISTOHIGH);
    return 0;
}

/*
int readscores(int limit, double tb[]) {
    int i = 0;
    while (i < limit && scanf("%lf", &tb[i]) == 1) ++i;
    return i;
}
*/

int readscores(int limit, double tb[]) {
    int i = 0, line = 1;
    double x;

    for ( ; i < limit && scanf("%lf", &x) == 1; ++line) {
        if (0.0 <= x && x <= 100.0) {
            tb[i] = x;
            ++i;
        }
        else printf("Data error, line %d\n", line);
    }

    if (i == limit && scanf("%lf", &x) == 1) { /* 还有数据 */
        printf("Too many data. Output is not correct.\n");
        return 0;
    }

    return i;
}

void statistics(int n, double tb[]) {
    int i;
    double s, sum, avr;

    if (n <= 1) {
        printf("Data too few."
               " Can't produce mean and standard-deviation.\n");
        return;
    }

    for (sum = 0.0, i = 0; i < n; ++i) sum += tb[i];
    avr = sum/n;
    for (sum = 0.0, i = 0; i < n; ++i)
        sum += (tb[i] - avr)*(tb[i] - avr);
    s = sqrt(sum/(n-1));

    printf("Total students: %d\n", n);
    printf("Average score: %f\n", avr);
    printf("Standard deviation: %f\n\n", s);
}

void prtHH(int n) {
    int i;
    for (i = 0; i < n; ++i) putchar('H');
}

enum { SEGLEN = 5,
    HISTONUM = (100/SEGLEN)+1 };

void histogram(int n, double tb[], int high) {
    int i, mx;
    int segs[HISTONUM];

    if (n == 0) return;

    for (i = 0; i < HISTONUM; ++i) segs[i] = 0; /* 初始化 */
    for (i = 0; i < n; ++i) /* 统计各分段人数 */
        segs[(int)tb[i]/SEGLEN]++;

    for (mx = 1, i = 0; i < HISTONUM; ++i) /* 为规范化找出最大个数 */
        if (segs[i] > mx) mx = segs[i];

    for (i = 0; i < HISTONUM; ++i) { /* 输出 */
        printf("<%3d: %4d|", (i+1)*SEGLEN, segs[i]);
        prtHH(segs[i]*high/mx);
        putchar('\n');
    }
    putchar('\n');
}


