From 709d7811062d73589b693cc308d973713f475ee8 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Mon, 13 Oct 2025 16:46:26 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B7=D0=B0=D0=B3=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab01.sln | 31 +++++++++++++++++++++++ lab01/lab01.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 lab01.sln create mode 100644 lab01/lab01.cpp diff --git a/lab01.sln b/lab01.sln new file mode 100644 index 0000000..67047d7 --- /dev/null +++ b/lab01.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34024.191 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lab01", "lab01\lab01.vcxproj", "{EBF957AB-9D20-46E3-9D0A-D7A883E0071C}" +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 + {EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Debug|x64.ActiveCfg = Debug|x64 + {EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Debug|x64.Build.0 = Debug|x64 + {EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Debug|x86.ActiveCfg = Debug|Win32 + {EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Debug|x86.Build.0 = Debug|Win32 + {EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Release|x64.ActiveCfg = Release|x64 + {EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Release|x64.Build.0 = Release|x64 + {EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Release|x86.ActiveCfg = Release|Win32 + {EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CE3404EF-11FE-4EC1-B337-9F770D1EEA0A} + EndGlobalSection +EndGlobal diff --git a/lab01/lab01.cpp b/lab01/lab01.cpp new file mode 100644 index 0000000..b588850 --- /dev/null +++ b/lab01/lab01.cpp @@ -0,0 +1,65 @@ +#include +#include +using namespace std; + +int main() { + const size_t SCREEN_WIDTH = 80; + const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; + int i,j; + string a,b,c; + size_t number_count, bin_count; + cerr << "Enter number count: "; + cin >> number_count; + cerr << "Enter colichestvo corzin: "; + cin >> bin_count; + vector bins(bin_count); + vector numbers(number_count); + for (i = 0; i < number_count; i++) { + cin >> numbers[i]; + } + double min = numbers[0]; + double max = numbers[0]; + for (double x : numbers) { + if (x < min) { + min = x; + } + else if (x > max) { + max = x; + } + } + 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++) { + 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]++; + } + } + int maxlen = 0; + for (int j = 0; j < bin_count; j++) + { + if (maxlen < bins[j]) maxlen = bins[j]; + } + for (int j = 0; j < bin_count; j++) + { + if (bins[j] < 100) cout << " "; + if (bins[j] < 10) cout << " "; + cout << bins[j] << "|"; + size_t height = bins[j]; + if (maxlen > MAX_ASTERISK) + { + if (maxlen != bins[j]) height = MAX_ASTERISK * (static_cast(bins[j]) / maxlen); + else if (maxlen == bins[j]) height = MAX_ASTERISK; + } + for (int i = 0; i < height; i++) cout << "*"; + cout << "\n"; + } + return 0; +} \ No newline at end of file