From 77d3f426348d11cccfaa6bea0dd8e4f98abbd4a2 Mon Sep 17 00:00:00 2001 From: LykovaYA Date: Thu, 21 Nov 2024 20:34:26 +0300 Subject: [PATCH] =?UTF-8?q?code:=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=B0=20?= =?UTF-8?q?=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 --- lab34.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lab34.sln | 31 ++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 lab34.cpp create mode 100644 lab34.sln diff --git a/lab34.cpp b/lab34.cpp new file mode 100644 index 0000000..01695b0 --- /dev/null +++ b/lab34.cpp @@ -0,0 +1,70 @@ +#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 amount of numbers \n"; + cin >> number_count; + vector numbers(number_count); + for (size_t i = 0; i < number_count; i++) { + cerr << "Input number " << i + 1 << endl; + cin >> numbers[i]; + } + double minc, maxc; + minc = maxc = numbers[0]; + for (size_t i = 1; i < number_count; i++) { + if (numbers[i] < minc) { + minc = numbers[i]; + } + else if (numbers[i] > maxc) { + maxc = numbers[i]; + } + } + size_t bin_count; + cerr << "Input number of bins \n"; + cin >> bin_count; + vector bins(bin_count); + double bin_size = (maxc - minc) / bin_count; + size_t bin_max_size = 0; + 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 = minc + j * bin_size; + auto hi = minc + (j + 1) * bin_size; + if ((lo <= numbers[i]) && (numbers[i] < hi)) { + bins[j]++; + found = true; + if (bins[j] > bin_max_size) { + bin_max_size = bins[j]; + } + } + } + if (!found) { + bins[bin_count - 1]++; + if (bins[bin_count - 1] > bin_max_size) { + bin_max_size = bins[bin_count - 1]; + } + } + } + double k = double(MAX_ASTERISK) / bin_max_size; + if (k > 1) { + k = 1; + } + for (size_t bin = 0; bin < bin_count; bin++) { + if (bins[bin] < 100) { + cout << " "; + } + if (bins[bin] < 10) { + cout << " "; + } + cout << bins[bin] << "|"; + for (size_t i = 0; i < bin * k; i++) { + cout << "*"; + } + cout << endl; + } + return 0; +} \ No newline at end of file diff --git a/lab34.sln b/lab34.sln new file mode 100644 index 0000000..13e2f78 --- /dev/null +++ b/lab34.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34408.163 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lab34", "lab34.vcxproj", "{552D18F9-D4D0-4EBB-8C60-7052DA815781}" +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 + {552D18F9-D4D0-4EBB-8C60-7052DA815781}.Debug|x64.ActiveCfg = Debug|x64 + {552D18F9-D4D0-4EBB-8C60-7052DA815781}.Debug|x64.Build.0 = Debug|x64 + {552D18F9-D4D0-4EBB-8C60-7052DA815781}.Debug|x86.ActiveCfg = Debug|Win32 + {552D18F9-D4D0-4EBB-8C60-7052DA815781}.Debug|x86.Build.0 = Debug|Win32 + {552D18F9-D4D0-4EBB-8C60-7052DA815781}.Release|x64.ActiveCfg = Release|x64 + {552D18F9-D4D0-4EBB-8C60-7052DA815781}.Release|x64.Build.0 = Release|x64 + {552D18F9-D4D0-4EBB-8C60-7052DA815781}.Release|x86.ActiveCfg = Release|Win32 + {552D18F9-D4D0-4EBB-8C60-7052DA815781}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8BBB87CA-7BC3-45B8-9195-8D80F04027F1} + EndGlobalSection +EndGlobal