|
|
|
@ -5,40 +5,28 @@ using namespace std;
|
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
struct Input {
|
|
|
|
|
vector<double> numbers;
|
|
|
|
|
size_t bin_count{};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
input_data() {
|
|
|
|
|
size_t number_count;
|
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
|
cin >> number_count;
|
|
|
|
|
|
|
|
|
|
vector<double> numbers(number_count);
|
|
|
|
|
cerr << "Enter numbers: ";
|
|
|
|
|
for(size_t i = 0; i < number_count; i++)
|
|
|
|
|
{
|
|
|
|
|
cin >> numbers[i];
|
|
|
|
|
Input in;
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
|
for (size_t i = 0; i < number_count; i++) {
|
|
|
|
|
cin >> in.numbers[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t bin_count;
|
|
|
|
|
cin >> in.bin_count;
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
|
cin >> bin_count;
|
|
|
|
|
int ef, ps=0;
|
|
|
|
|
if (bin_count==0)
|
|
|
|
|
{
|
|
|
|
|
ef=(sqrt(number_count));
|
|
|
|
|
if (ef>25)
|
|
|
|
|
{
|
|
|
|
|
ps=1+(log2(number_count));
|
|
|
|
|
cout<<"ps: " << ps<<endl;
|
|
|
|
|
bin_count=ps;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
cout<<"ef: " << ef<<endl;
|
|
|
|
|
bin_count=ef;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
double min = numbers[0];
|
|
|
|
|
double max = numbers[0];
|
|
|
|
|
void
|
|
|
|
|
find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|
|
|
|
min = numbers[0];
|
|
|
|
|
for (double x : numbers)
|
|
|
|
|
{
|
|
|
|
|
if (x < min)
|
|
|
|
@ -50,28 +38,37 @@ int main()
|
|
|
|
|
max = x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vector<size_t> make_histogram(const vector<double> numbers, size_t bin_count){
|
|
|
|
|
vector<size_t> bins(bin_count);
|
|
|
|
|
double bin_size = (max-min)/bin_count;
|
|
|
|
|
for (size_t i = 0; i < number_count; i++)
|
|
|
|
|
{
|
|
|
|
|
double max, min = 0;
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
double bin_size = (max - min) / bin_count;
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < numbers.size(); i++) {
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
|
|
|
|
|
{
|
|
|
|
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++) {
|
|
|
|
|
auto lo = min + j * bin_size;
|
|
|
|
|
auto hi = min + (j + 1) * bin_size;
|
|
|
|
|
if ( (numbers[i] >= lo) && (numbers[i] < hi) )
|
|
|
|
|
{
|
|
|
|
|
if ((lo <= numbers[i]) && (numbers[i] < hi)) {
|
|
|
|
|
bins[j]++;
|
|
|
|
|
found = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found)
|
|
|
|
|
{
|
|
|
|
|
bins[bin_count-1]++;
|
|
|
|
|
}
|
|
|
|
|
if (!found) {
|
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
size_t max_count = bins[0];
|
|
|
|
|
return bins;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void show_histogram_text (vector<size_t> bins){
|
|
|
|
|
size_t max_count = bins[0];
|
|
|
|
|
for(size_t x: bins)
|
|
|
|
|
{
|
|
|
|
|
if(x > max_count)
|
|
|
|
@ -126,5 +123,14 @@ int main()
|
|
|
|
|
cout << "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
auto in = input_data();
|
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
show_histogram_text(bins);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|