From f827c405aa2e6711cb145a76108af1177e88ddec Mon Sep 17 00:00:00 2001 From: SidoraDA Date: Sun, 14 May 2023 18:03:53 +0400 Subject: [PATCH] =?UTF-8?q?code:=20=D0=BA=D0=BE=D0=B4=20=D0=BB=D1=801?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- !thecode.txt | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 !thecode.txt diff --git a/!thecode.txt b/!thecode.txt new file mode 100644 index 0000000..5262942 --- /dev/null +++ b/!thecode.txt @@ -0,0 +1,101 @@ +#include +#include + + +using namespace std; +const size_t SCREEN_WIDTH = 80; +const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + +int main() +{ + size_t i, j; //ԅ(≖‿≖ԅ)// + size_t histo_height; + size_t number_count; + size_t bin_count; + cerr << "Enter number count: "; + cin >> number_count; + vector numbers(number_count); + for (i = 0; i < number_count; i++) + { + cerr << "Number[" << i << "] is "; + cin >> numbers[i]; + } + + + double max = numbers[0]; + double min = numbers[0]; + for (i = 0; i < number_count; i++) + { + if (numbers[i] < min) + min = numbers[i]; + + else if (numbers[i] > max) + max = numbers[i]; + } + cerr << "Enter bin count: "; + cin >> bin_count; + + cerr << "Enter histo height: "; + cin >> histo_height; + size_t table_height = histo_height / bin_count; + + vector bins(bin_count); + double bin_size = (max - min) / bin_count; + size_t max_count = 0; + for (i = 0; i < number_count; i++) + { + bool found = false; + for (j = 0; (j < bin_count - 1) && !found; j++) + { + double lo = min + j * bin_size; + double hi = min + (j + 1) * bin_size; + if ((lo <= numbers[i]) && (numbers[i] < hi)) + { + bins[j]++; + found = true; + } + } + if (!found) + { + bins[bin_count - 1]++; + } + for (size_t i = 0; i < bin_count; i++) + { + if (bins[i] > max_count) + max_count = bins[i]; + + } + } + size_t height = 0; + for (i = 0; i < bin_count; i++) + { + + for (size_t a = 0; a < table_height; a++) + { + if (bins[i] < 100) + cout << " "; + if (bins[i] < 10) + cout << " "; + cout << bins[i] << "|"; + if (max_count > MAX_ASTERISK) + { + for (j = 0; j < (height = MAX_ASTERISK * (static_cast(bins[i]) / max_count)); j++) + { + cout << "*"; + + } + cout << endl; + } + else + { + for (j = 0; j < bins[i]; j++) + { + cout << "*"; + } + cout << endl; + } + + } + + } +}