|
|
|
@ -3,51 +3,60 @@
|
|
|
|
|
#include <math.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
//Ââîä
|
|
|
|
|
size_t number_count;
|
|
|
|
|
size_t bin_count;
|
|
|
|
|
float n = 0;
|
|
|
|
|
struct Input {
|
|
|
|
|
vector<double> numbers;
|
|
|
|
|
size_t bin_count{};
|
|
|
|
|
float n;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
input_data() {
|
|
|
|
|
size_t number_count;
|
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
|
cin >> number_count;
|
|
|
|
|
|
|
|
|
|
vector<double> numbers(number_count);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i<number_count;i++) {
|
|
|
|
|
Input in;
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
|
for (size_t i = 0; i < number_count; i++) {
|
|
|
|
|
cerr << "Enter number " << i+1 << ": ";
|
|
|
|
|
cin >> numbers[i];}
|
|
|
|
|
cin >> in.numbers[i];}
|
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
|
cin >> bin_count;
|
|
|
|
|
|
|
|
|
|
if (bin_count==0){
|
|
|
|
|
bin_count = sqrt(number_count);
|
|
|
|
|
n = 1;
|
|
|
|
|
if (bin_count > 25){
|
|
|
|
|
bin_count = 1 + log2(number_count);
|
|
|
|
|
n = 2;}}
|
|
|
|
|
cin >> in.bin_count;
|
|
|
|
|
|
|
|
|
|
vector<double> bins(bin_count);
|
|
|
|
|
in.n = 0;
|
|
|
|
|
if (in.bin_count==0){
|
|
|
|
|
in.bin_count = sqrt(number_count);
|
|
|
|
|
in.n = 1;
|
|
|
|
|
if (in.bin_count > 25){
|
|
|
|
|
in.bin_count = 1 + log2(number_count);
|
|
|
|
|
in.n = 2;}}
|
|
|
|
|
|
|
|
|
|
//îáðàáîòêà
|
|
|
|
|
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 = numbers[0];
|
|
|
|
|
double max = numbers[0];
|
|
|
|
|
for (double x : numbers) {
|
|
|
|
|
if (x < min) {
|
|
|
|
|
min = x;
|
|
|
|
|
}
|
|
|
|
|
else if (x > max) {
|
|
|
|
|
max = x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
double min, max;
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
double bin_size = (max - min) / bin_count;
|
|
|
|
|
vector<size_t> bins(bin_count);
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < number_count; i++) {
|
|
|
|
|
for (size_t i = 0; i < numbers.size(); i++) {
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++) {
|
|
|
|
|
auto lo = min + j * bin_size;
|
|
|
|
@ -60,9 +69,13 @@ int main()
|
|
|
|
|
if (!found) {
|
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return bins;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Âûâîä
|
|
|
|
|
void
|
|
|
|
|
show_histogram_text(const vector<size_t>& bins, size_t bin_count, float n){
|
|
|
|
|
if (n != 0){
|
|
|
|
|
cout << "bin count = " << bin_count;
|
|
|
|
|
if (n == 1)
|
|
|
|
@ -78,5 +91,13 @@ int main()
|
|
|
|
|
for (size_t j = 0; j < bins[i]; j++){
|
|
|
|
|
cout << "*";}
|
|
|
|
|
cout << '\n';}
|
|
|
|
|
}
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
auto in = input_data();
|
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
show_histogram_text(bins, in.bin_count, in.n);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|