From 39c1218db408a2d7c22e66cf9a382ebb537393ab Mon Sep 17 00:00:00 2001 From: "PARZIVAL (BreganIM)" Date: Thu, 1 May 2025 21:20:39 +0300 Subject: [PATCH] =?UTF-8?q?code:=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20text.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- text.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 text.cpp diff --git a/text.cpp b/text.cpp new file mode 100644 index 0000000..ef0b904 --- /dev/null +++ b/text.cpp @@ -0,0 +1,33 @@ +#include "text.h" +#include +#include +using namespace std; + +const size_t SCREEN_WIDTH = 80; +const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + +void show_histogram_text(const vector& bins) { + size_t max_count = bins[0]; + for (size_t count : bins) { + if (count > max_count) + max_count = count; + } + for (size_t j = 0; j < bins.size(); j++) { + if (bins[j] < 100) cout << " "; + if (bins[j] < 10) cout << " "; + cout << bins[j] << "|"; + + size_t height = 0; + if (max_count > MAX_ASTERISK) { + height = static_cast( + static_cast(bins[j]) / max_count * MAX_ASTERISK + ); + } + else { + height = bins[j]; + } + for (size_t i = 0; i < height; i++) + cout << "*"; + cout << endl; + } +}