#include "text.h" #include #include using namespace std; void show_histogram_text(const vector& bins) { const size_t SCREEN_WIDTH = 80; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; size_t max_count = 0; for (size_t count : bins) { if (count > max_count) { max_count = count; } } for (size_t count : bins) { // Выводим количество с выравниванием if (count < 10) { cout << " " << count << "|"; } else if (count < 100) { cout << " " << count << "|"; } else { cout << count << "|"; } size_t height = 0; if (max_count <= MAX_ASTERISK) { height = count; } else { height = MAX_ASTERISK * (static_cast(count) / max_count); } for (size_t i = 0; i < height; i++) { cout << "*"; } cout << "\n"; } }