#include #include #include "text.h" const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; void show_histogram_text(std::vector &bins, size_t bin_count) { int max_count = bins[0]; for (int i = 0; i < bin_count; i++) { if (bins[i] > max_count) { max_count = bins[i]; } } std::vector height(bin_count); for (int i = 0; i < bin_count; i++) { if (bins[i] > MAX_ASTERISK) { height[i] = (MAX_ASTERISK * bins[i]) / max_count; } else height[i] = bins[i]; } for (int i = 0; i < bin_count; i++) { if (bins[i] < 100) { std::cout << " "; } if (bins[i] < 10) { std::cout << " " ; } std::cout << bins[i] << "|"; for (int j = 0; j < height[i]; j++) { std::cout << "*"; } std::cout << std::endl; } }