From 42c1ece97fbad3cffe571f84784735e7b937f126 Mon Sep 17 00:00:00 2001 From: Artyom Date: Sat, 18 May 2024 15:29:29 +0300 Subject: [PATCH] =?UTF-8?q?Build:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=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=20=D0=B8=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lab34.cbp | 40 ++++++++++++++++++++++++++++++ main.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 Lab34.cbp create mode 100644 main.cpp diff --git a/Lab34.cbp b/Lab34.cbp new file mode 100644 index 0000000..25bf332 --- /dev/null +++ b/Lab34.cbp @@ -0,0 +1,40 @@ + + + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e9149cb --- /dev/null +++ b/main.cpp @@ -0,0 +1,74 @@ +#include +#include + +using namespace std; + +const size_t SCREEN_WIDTH = 80; +const size_t MAX_LENGTH = SCREEN_WIDTH - 3 - 1; + +int main() { + int number_count, bin_count, i, j; + cerr << "Enter number count:" << endl; + cin >> number_count; + vector numbers(number_count); + cerr << "Enter numbers:" << endl; + for (i = 0;i < number_count; i++) { + cin >> numbers[i]; + } + auto min = numbers[0]; + auto max = numbers[0]; + for (auto x : numbers) { + if (x < min) { + min = x; + } + else if (x > max) { + max = x; + } + } + cerr << "Enter bin count:" << endl; + cin >> bin_count; + double bin_size = (max - min) / bin_count; + vector bins(bin_count); + for (i = 0; i < number_count; i++) { + bool found = false; + for (j = 0; (j < bin_count - 1) && !found ; j++) { + if ((min + j * bin_size <= numbers[i]) && (numbers[i] < min + (j + 1) * bin_size)) { + bins[j] += 1; + found = true; + } + } + if (!found) bins[bin_count - 1]++; + } + auto max_count = bins[0]; + for (auto x : bins) { + if (x > max_count) { + max_count = x; + } + } + for (i = 0; i < bin_count; i++) { + j = 100; + while (bins[i] < j) { + cout << " "; + j /= 10; + } + cout << bins[i] << "|"; + if (max_count > MAX_LENGTH) { + auto count = bins[i]; + size_t height = MAX_LENGTH * (static_cast(count) / max_count); + j = 0; + while (j < height) { + cout << "*"; + j++; + } + } + else { + j = 0; + while (j < bins[i]) { + cout << "*"; + j++; + } + } + cout << endl; + } + return 0; +}