From aff7ed7d57b34f24d7aed952b04532a92c4adf10 Mon Sep 17 00:00:00 2001 From: "Daniil (FilippovDY)" Date: Wed, 10 Apr 2024 16:31:45 +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=D0=B8=D0=B5=20main,=20project,=20gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++ Lab01.cbp | 38 ++++++++++++++++++ main.cpp | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+) create mode 100644 .gitignore create mode 100644 Lab01.cbp create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..546bf6e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/bin +/obj +*.layout +*.depend \ No newline at end of file diff --git a/Lab01.cbp b/Lab01.cbp new file mode 100644 index 0000000..88781ad --- /dev/null +++ b/Lab01.cbp @@ -0,0 +1,38 @@ + + + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..5912556 --- /dev/null +++ b/main.cpp @@ -0,0 +1,113 @@ +#include +#include + +using namespace std; +int main() +{ + const size_t SCREEN_WIDTH = 80; + const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + size_t number_count; + cerr << "Enter number count: "; + cin >> number_count; + vector numbers(number_count); + + for(size_t i=0; i < number_count; i++) + { + cin >> numbers[i]; + } + + size_t bin_count; + cerr << "Enter bin count: "; + cin >> bin_count; + vector bins (bin_count); + + double min = numbers[0]; + double max = numbers[0]; + + for (double x : numbers) + { + if (x < min) + { + min = x; + } + else if (x > max) + { + max = x; + } + } + + double bin_size = (max - min) / bin_count; + + for (size_t i = 0; i < number_count; i++) + { + bool found = false; + for (size_t j = 0; (j < bin_count - 1) && !found; j++) + { + auto lo = min + j * bin_size; + auto hi = min + (j+1) * bin_size; + if ((lo <= numbers[i]) && (numbers[i] < hi)) + { + bins[j]++; + found = true; + } + } + if (!found) + { + bins[bin_count - 1]++; + } + } + + int max_count = 0; + for (size_t i = 0; i < bin_count; i++) + { + if (bins[i] > max_count) + { + max_count = bins[i]; + } + } + if (max_count > MAX_ASTERISK) + { + for (int i = 0; i < bin_count; i++) + { + size_t height = MAX_ASTERISK * (static_cast(bins[i]) / max_count); + if (bins[i] < 100) + { + cout << " "; + if (bins[i] < 10) + { + cout << " "; + } + } + cout << bins[i] << "|"; + for (size_t j = 0; j < height; j++) + { + cout << "*"; + } + cout << endl; + } + } + + else + { + for (int i = 0; i < bin_count; i++) + { + if (bins[i] < 100) + { + cout << " "; + if (bins [i] < 10) + { + cout << " "; + } + } + cout << bins[i] << "|"; + for (int j = 0; j < bins[i]; j++) + { + cout << "*"; + } + cout << endl; + } + } +} + + +