#include "histogram.h" struct Input { vector vec; size_t korz{}; }; Input input_data() { Input in; size_t n, korz; cerr << "Number of elem "; cin >> n; in.vec.resize(n); for (size_t i = 0; i < n; i++) cin >> in.vec[i]; cerr << "Enter bin count: "; cin >> in.korz; return in; } int main() { auto in = input_data(); auto bins = make_histogram(in.korz, in.vec); bool gigant = false; auto spaces = 0; size_t mx_count = 0; for (auto x : bins) { if (x > 76) { gigant = true; } if (x > mx_count) { mx_count = x; } auto len = 0; while (x > 0) { x /= 10; len++; } if (len > spaces) { spaces = len; } } if (spaces == 1) { for (size_t i = 0; i < bins.size(); i++) { std::cout << " " << bins[i] << "|"; if (gigant) { if (bins[i] == mx_count) { for (size_t j = 0; j < 76; j++) { std::cout << "*"; } } else { for (size_t j = 0; j < 76 * static_cast(bins[i]) / mx_count; j++) { std::cout << "*"; } } } else { for (size_t j = 0; j < bins[i]; j++) { std::cout << "*"; } std::cout << std::endl; } } } else { for (size_t i = 0; i < bins.size(); i++) { int len = 1; int k = bins[i]; for (; k /= 10; ++len); while (len < spaces) { std::cout << " "; len++; } std::cout << bins[i]; std::cout << "|"; if (gigant) { if (bins[i] == mx_count) { for (size_t j = 0; j < 76; j++) { std::cout << "*"; } } else { for (size_t j = 0; j < (76 * static_cast(bins[i]) / mx_count - 1); j++) { std::cout << "*"; } } } else { for (size_t j = 0; j < bins[i]; j++) { std::cout << "*"; } } std::cout << std::endl; } } }