From 8ac701d9ef5f69c224fc8aad4e6b1d7aac4e332e Mon Sep 17 00:00:00 2001 From: Artyom Date: Sat, 18 May 2024 15:46:43 +0300 Subject: [PATCH] =?UTF-8?q?Code:=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=20=D0=BC?= =?UTF-8?q?=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=D1=83=D0=BC=D0=B0\=D0=BC=D0=B8?= =?UTF-8?q?=D0=BD=D0=B8=D0=BC=D1=83=D0=BC=D0=B0=20=D0=B2=D1=8B=D0=BD=D0=B5?= =?UTF-8?q?=D1=81=D0=B5=D0=BD=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=83=D1=8E=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 53689d0..35b7e93 100644 --- a/main.cpp +++ b/main.cpp @@ -28,11 +28,15 @@ input_data(){ return in; } -int main() { - auto in = input_data(); - auto min = in.numbers[0]; - auto max = in.numbers[0]; - for (auto x : in.numbers) { +void +find_minmax(const std::vector& numbers, double& min, double& max, bool& res){ + if (numbers.size() == 0){ + res = false; + return; + } + min = numbers[0]; + max = numbers[0]; + for (auto x : numbers) { if (x < min) { min = x; } @@ -40,6 +44,18 @@ int main() { max = x; } } +} + +int main() { + auto in = input_data(); + auto min = in.numbers[0]; + auto max = in.numbers[0]; + bool res = true; + find_minmax(in.numbers, min, max, res); + if (res == false){ + cerr << "Number of elements cannot be equal to zero"; + exit(1); + } double bin_size = (max - min) / in.bin_count; vector bins(in.bin_count); for (auto x : in.numbers) {