From b8a0214a0f8b90ef34e47e2e2d40e0d9085fd27e Mon Sep 17 00:00:00 2001
From: KriviAS <KriviAS@mpei.ru>
Date: Sun, 21 Apr 2024 16:23:35 +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=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2?=
 =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D1=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 labaa6.cbp |  40 ++++++++++++++++++++
 main.cpp   | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 146 insertions(+)
 create mode 100644 labaa6.cbp
 create mode 100644 main.cpp

diff --git a/labaa6.cbp b/labaa6.cbp
new file mode 100644
index 0000000..4119a13
--- /dev/null
+++ b/labaa6.cbp
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+	<FileVersion major="1" minor="6" />
+	<Project>
+		<Option title="labaa6" />
+		<Option pch_mode="2" />
+		<Option compiler="gcc" />
+		<Build>
+			<Target title="Debug">
+				<Option output="bin/Debug/labaa6" prefix_auto="1" extension_auto="1" />
+				<Option object_output="obj/Debug/" />
+				<Option type="1" />
+				<Option compiler="gcc" />
+				<Compiler>
+					<Add option="-g" />
+				</Compiler>
+			</Target>
+			<Target title="Release">
+				<Option output="bin/Release/labaa6" prefix_auto="1" extension_auto="1" />
+				<Option object_output="obj/Release/" />
+				<Option type="1" />
+				<Option compiler="gcc" />
+				<Compiler>
+					<Add option="-O2" />
+				</Compiler>
+				<Linker>
+					<Add option="-s" />
+				</Linker>
+			</Target>
+		</Build>
+		<Compiler>
+			<Add option="-Wall" />
+			<Add option="-fexceptions" />
+		</Compiler>
+		<Unit filename="main.cpp" />
+		<Extensions>
+			<lib_finder disable_auto="1" />
+		</Extensions>
+	</Project>
+</CodeBlocks_project_file>
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..fa30878
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,106 @@
+#include <iostream>
+#include <conio.h>
+#include <vector>
+using namespace std;
+int main()
+{
+    const size_t SCREEN_WIDTH = 80;
+    const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
+    int i, j;
+    double num;
+    size_t number_count, bin_count;
+    cerr << "Enter number count: " << "\n";
+    cin >> number_count;
+    vector<double> numbers(number_count);
+    for (i = 0; i < number_count; i++)
+    {
+        cin >> num;
+        numbers[i] = num;
+    }
+    cerr << "Enter bin count: " << "\n";
+    cin >> bin_count;
+    vector<size_t> bins(bin_count);
+    for (i = 0; i < bin_count; i++)
+    {
+        bins[i] = 0;
+    }
+    double min_number = numbers[0];
+    double max_number = numbers[0];
+    for (double x : numbers)
+    {
+        if (x < min_number)
+        {
+            min_number = x;
+        }
+        else if (x > max_number)
+        {
+            max_number = x;
+        }
+    }
+    double bin_size = (max_number - min_number) / 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_number + j * bin_size;
+            auto hi = min_number + (j + 1) * bin_size;
+            if ((lo <= numbers[i]) && (numbers[i] < hi))
+            {
+                bins[j]++;
+                found = true;
+            }
+        }
+        if (!found)
+        {
+            bins[bin_count - 1]++;
+        }
+    }
+    size_t max_bin_capacity = bins[0];
+    for (size_t x : bins)
+    {
+        if (x > max_bin_capacity)
+        {
+            max_bin_capacity = x;
+        }
+    }
+    size_t height = 0;
+    for (i = 0; i < bin_count; i++)
+    {
+        if (bins[i] < 10)
+        {
+            cout << "  " << bins[i] << "|";
+        }
+        if ((bins[i] < 100) && (bins[i] > 9))
+        {
+            cout << " " << bins[i] << "|";
+        }
+        if (bins[i] >= 100)
+        {
+            cout <<  bins[i] << "|";
+        }
+        if (bins[i] > 76){
+        height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_bin_capacity);
+        }
+        else {
+            height = bins[i];
+        }
+
+        for (j = 0; j < height; j++)
+        {
+            if (i > 0){
+                if (j == bins[i-1] - 1){
+                    cout<<"^";
+                }}
+            if (i < bin_count){
+            if (j == bins[i+1] - 1)
+                cout<<"v";
+            else
+                cout<<"*";}
+
+        }
+        cout << "\n";
+
+    }
+    return 0;
+}