diff --git a/main.cpp b/main.cpp index fac04ab..a0f4363 100644 --- a/main.cpp +++ b/main.cpp @@ -40,8 +40,8 @@ void find_minmax(const vector& numbers, double& minimum, double& maximum int main () { vector numbers; vector baskets; - size_t numbers_count; - size_t baskets_count; +// size_t numbers_count; +// size_t baskets_count; size_t baskets_max_count; const size_t screen_width = 80; const size_t max_asterisk = screen_width - 3 - 1; @@ -51,36 +51,15 @@ int main () { cout.precision(4); Input in = input_data(); + baskets.resize(in.bin_count); -// cerr << "Введите кол-во чисел в строке: "; -// cin >> numbers_count; -// numbers.resize(numbers_count); -// -// cerr << "Введите строку чисел: "; -// for (float& i : numbers) { -// cin >> i; -// } -// -// cerr << "Введите кол-во корзин: "; -// cin >> baskets_count; -// - //baskets.resize(baskets_count); - -// basket_max = numbers[0]; -// for (int i : numbers) { -// if (i > basket_max) basket_max = i; -// } -// basket_min = numbers[0]; -// for (int i : numbers) { -// if (i < basket_min) basket_min = i; -// } find_minmax(in.numbers, basket_min, basket_max); basket_size = (basket_max - basket_min) / in.bin_count; for (int i = 0; i < in.bin_count; i++) { - for (int j = 0; j < numbers_count; j++) { - if ((numbers[j] >= (basket_min + i * basket_size) and numbers[j] < (basket_min + (i + 1) * basket_size)) or (i == in.bin_count - 1 and numbers[j] == basket_max)) { + for (int j = 0; j < in.numbers.size(); j++) { + if ((in.numbers[j] >= (basket_min + i * basket_size) and in.numbers[j] < (basket_min + (i + 1) * basket_size)) or (i == in.bin_count - 1 and in.numbers[j] == basket_max)) { baskets[i]++; } } @@ -91,8 +70,8 @@ int main () { if (i > baskets_max_count) baskets_max_count = i; } - for (int i = 0; i < baskets_count; i++) { - size_t height = baskets[0]; + for (int i = 0; i < in.bin_count; i++) { + size_t height = baskets[i]; if (baskets_max_count > max_asterisk) { height = max_asterisk * (static_cast(baskets[i]) / baskets_max_count); }