From 8fa89f30a22cda698ee7eb2523e2fedf6f6ff6d2 Mon Sep 17 00:00:00 2001 From: DenisovPS Date: Sun, 4 Jun 2023 21:41:40 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D1=85=D0=BE=D0=B4=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9=20=D0=BA=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 main.cpp diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..5e6f9fd --- /dev/null +++ b/main.cpp @@ -0,0 +1,102 @@ +#include +#include +using namespace std; + +int main() +{ + size_t numbers, columns, count; + float minn, maxx, diff, lo, hi; + + cerr << "Quantity of numbers = "; cin >> numbers; + vector xs(numbers); + cerr << "Enter your numbers: "; + + for (int i = 0; i < numbers; ++i) + { + cin >> xs[i]; + } + + cerr << "Columns = "; cin >> columns; + vector a(columns); + + maxx = xs[0]; + minn = xs[0]; + for (int i = 0; i < numbers; i++) + { + if (xs[i] > maxx) + maxx = xs[i]; + else + { + if (xs[i] < minn) + minn = xs[i]; + } + } + + + diff = (maxx - minn) / columns; + lo = minn; + + size_t max_count = 0; + for (int i = 0; i < columns; ++i) + { + count = 0; + + if (i != columns - 1) + { + hi = lo + diff; + } + else + { + hi = maxx; + } + for (int j = 0; j < numbers; j++) + { + if (i == 0) + { + if ((xs[j] >= lo) && (xs[j] <= hi)) + count++; + } + + else + { + if ((xs[j] > lo) && (xs[j] <= hi)) + count++; + } + } + a[i] = count; + lo = hi; + + if (max_count < a[i]) + max_count = a[i]; + } + + const size_t SCREEN_WIDTH = 80; + const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + size_t height; + for (int i = 0; i < columns; i++) + { + + if (a[i] == 0) + continue; + + if (a[i] < 10) + cout << " "; + else + if (a[i] < 100) + cout << " "; + + cout << a[i] << "|"; + + if (max_count > MAX_ASTERISK) + height = MAX_ASTERISK * (static_cast(a[i]) / max_count); + else + height = a[i]; + + for (int j = 0; j < height; j++) + { + cout << "*"; + } + cout << endl; + } + +}