#include "text.h"
#include <iostream>

void show_histogram(const std::vector<size_t>& bins) {


    bool gigant = false;
    auto spaces = 0;
    size_t mx_count = 0;

    for (auto x : bins) {
        if (x > 76) gigant = true;
        if (x > mx_count) mx_count = x;

        auto len = 0;
        auto num = x;
        while (num > 0) {
            num /= 10;
            len++;
        }
        if (len > spaces) spaces = len;
    }

    for (size_t i = 0; i < bins.size(); i++) {

        int len = 1;
        auto num = bins[i];
        for (; num /= 10; ++len);
        while (len < spaces) {
            std::cout << " ";
            len++;
        }
        std::cout << bins[i] << "|";


        if (gigant) {
            size_t stars = (mx_count > 0) ? (76 * bins[i] / mx_count) : 0;
            for (size_t j = 0; j < stars; j++) {
                std::cout << "*";
            }
        } else {
            for (size_t j = 0; j < bins[i]; j++) {
                std::cout << "*";
            }
        }
        std::cout << std::endl;
    }
}
