|
|
@ -3,6 +3,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
|
|
|
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Input {
|
|
|
|
struct Input {
|
|
|
|
vector<double> numbers;
|
|
|
|
vector<double> numbers;
|
|
|
|
size_t bin_count{};
|
|
|
|
size_t bin_count{};
|
|
|
@ -11,6 +15,7 @@ struct Input {
|
|
|
|
Input
|
|
|
|
Input
|
|
|
|
input_data() {
|
|
|
|
input_data() {
|
|
|
|
size_t number_count;
|
|
|
|
size_t number_count;
|
|
|
|
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
cin >> number_count;
|
|
|
|
cin >> number_count;
|
|
|
|
|
|
|
|
|
|
|
|
Input in;
|
|
|
|
Input in;
|
|
|
@ -20,51 +25,12 @@ input_data() {
|
|
|
|
cin >> in.numbers[i];
|
|
|
|
cin >> in.numbers[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
cin >> in.bin_count;
|
|
|
|
cin >> in.bin_count;
|
|
|
|
|
|
|
|
|
|
|
|
return in;
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|
|
|
|
|
|
|
min = numbers[0];
|
|
|
|
|
|
|
|
max = numbers[0];
|
|
|
|
|
|
|
|
for (double x : numbers) {
|
|
|
|
|
|
|
|
if (x < min) {
|
|
|
|
|
|
|
|
min = x;
|
|
|
|
|
|
|
|
} else if (x > max) {
|
|
|
|
|
|
|
|
max = x;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<size_t>
|
|
|
|
|
|
|
|
make_histogram(const vector<double>& numbers, size_t bin_count) {
|
|
|
|
|
|
|
|
double min, max;
|
|
|
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<size_t> bins(bin_count, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double bin_size = (max - min) / bin_count;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (double number : numbers) {
|
|
|
|
|
|
|
|
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 <= number && number < hi) {
|
|
|
|
|
|
|
|
bins[j]++;
|
|
|
|
|
|
|
|
found = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return bins;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
int
|
|
|
|
main() {
|
|
|
|
main() {
|
|
|
|
auto in = input_data();
|
|
|
|
auto in = input_data();
|
|
|
@ -72,3 +38,4 @@ main() {
|
|
|
|
show_histogram_text(bins);
|
|
|
|
show_histogram_text(bins);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|