From 360a44e401e3bdd74977055478712dad7e710b87 Mon Sep 17 00:00:00 2001 From: alextwix Date: Sat, 6 Sep 2025 21:43:27 +0300 Subject: [PATCH] start --- lab1.sln | 31 +++++++++++++++++++++++++ main.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 lab1.sln create mode 100644 main.cpp diff --git a/lab1.sln b/lab1.sln new file mode 100644 index 0000000..3fb0762 --- /dev/null +++ b/lab1.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35913.81 d17.13 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lab1", "lab1.vcxproj", "{A1A0B8CA-AC39-44A3-AF6E-466F6D691FDA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A1A0B8CA-AC39-44A3-AF6E-466F6D691FDA}.Debug|x64.ActiveCfg = Debug|x64 + {A1A0B8CA-AC39-44A3-AF6E-466F6D691FDA}.Debug|x64.Build.0 = Debug|x64 + {A1A0B8CA-AC39-44A3-AF6E-466F6D691FDA}.Debug|x86.ActiveCfg = Debug|Win32 + {A1A0B8CA-AC39-44A3-AF6E-466F6D691FDA}.Debug|x86.Build.0 = Debug|Win32 + {A1A0B8CA-AC39-44A3-AF6E-466F6D691FDA}.Release|x64.ActiveCfg = Release|x64 + {A1A0B8CA-AC39-44A3-AF6E-466F6D691FDA}.Release|x64.Build.0 = Release|x64 + {A1A0B8CA-AC39-44A3-AF6E-466F6D691FDA}.Release|x86.ActiveCfg = Release|Win32 + {A1A0B8CA-AC39-44A3-AF6E-466F6D691FDA}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8E747EBC-B0F8-4927-9A53-0B4F2A59C893} + EndGlobalSection +EndGlobal diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..8427d75 --- /dev/null +++ b/main.cpp @@ -0,0 +1,71 @@ +#include +#include +#include + +using namespace std; + +int main() { + setlocale(LC_ALL, "ru"); + + size_t number_count; + + cerr << "Введите количество чисел" << endl; + cin >> number_count; + + vector numbers(number_count); + + for (int i = 0; i < number_count; i++) { + cerr << "Введите число #" << i + 1 << endl; + cin >> numbers[i]; + } + + size_t bin_count; + + cerr << "Введите количество корзин" << endl; + cin >> bin_count; + + vector bins(bin_count); + + auto min_it = min_element(numbers.begin(), numbers.end()); + double min = *min_it; + auto max_it = max_element(numbers.begin(), numbers.end()); + double max = *max_it; + + 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]++; + } + } + + const size_t max_asterisk = 76; + auto max_count_it = max_element(bins.begin(), bins.end()); + double max_count = *max_count_it; + + size_t height; + + for (int i = 0; i < bin_count; i++) { + if (bins[i] < 10) { + cout << " "; + } + else if(bins[i] < 100) { + cout << " "; + } + cout << bins[i] << "|"; + height = 76 * (static_cast(bins[i]) / max_count); + for (int j = 0; j < height; j++) { + cout << "*"; + } + cout << endl; + } +} \ No newline at end of file