From bc866c8da4d6efbee69da50bcbf1f1fdef0f5d93 Mon Sep 17 00:00:00 2001 From: Danila Date: Sun, 23 Apr 2023 22:08:32 +0300 Subject: [PATCH] =?UTF-8?q?git:=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B8=D0=B7=20=D1=80=D0=B5=D0=BF=D1=8B=20=D1=83=D0=B4=D0=B0?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BD=D1=8B=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 - main.cpp | 140 ----------------------------------------------------- part3.cbp | 40 --------------- 3 files changed, 182 deletions(-) delete mode 100644 .gitignore delete mode 100644 main.cpp delete mode 100644 part3.cbp diff --git a/.gitignore b/.gitignore deleted file mode 100644 index fba4e61..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/obj -/bin diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 0f6ddd2..0000000 --- a/main.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include -#include -#include - -using namespace std; - -struct Input -{ - vector numbers; - size_t bin_count{}; -}; - -Input input_data() -{ - size_t number_count; - cin >> number_count; - - Input in; - in.numbers.resize(number_count); - for (size_t i = 0; i < number_count; i++) - { - cin >> in.numbers[i]; - } - cin>> in.bin_count; - return in; -} - -void -find_minmax(vector numbers, double& min, double& max) -{ - min = numbers[0]; - max = numbers[0]; - for (double x : numbers) - { - if (x < min) - { - min = x; - } - else if (x > max) - { - max = x; - } - } - return; -} - -auto make_histogram (vector numbers, size_t bin_count) -{ - double min; - double max; - find_minmax (numbers, min, max); - double bin_size = (max - min) / bin_count; - vector bins(bin_count); - - for (size_t i = 0; i < numbers.size(); 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]++; - } - } - - return bins; -} - - -void show_histogram_text(auto bins, size_t bin_count) -{ - const size_t screen_width = 80; - const size_t max_asterisk = screen_width - 3 - 1; - size_t i,j; - double max_count; - max_count = bins[0]; - for (i=0; i< bin_count; i++) - { - if (max_countmax_asterisk) - { - flag=true; - } - for (j = 0; j < bin_count; j++) - { - if (bins[j] < 100) - { - cout << " "; - } - if (bins[j] < 10) - { - cout << " "; - } - cout << bins[j] << "|"; - - if (flag) - { - height = max_asterisk * (static_cast(bins[j]) / max_count); - } - else - { - height=bins[j]; - } - for (i = 0; i < height; i++) - { - cout << "*"; - } - cout << endl; - } -} - - - - - - -int main() -{ - auto in = input_data(); - auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_text(bins, in.bin_count); - getch(); - return 0; -} diff --git a/part3.cbp b/part3.cbp deleted file mode 100644 index 877914b..0000000 --- a/part3.cbp +++ /dev/null @@ -1,40 +0,0 @@ - - - - - -