|
|
|
@ -1,8 +1,5 @@
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
|
const size_t MAX_STAR = SCREEN_WIDTH - 3 - 1;
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
struct Input
|
|
|
|
@ -14,7 +11,7 @@ struct Input
|
|
|
|
|
Input input_data()
|
|
|
|
|
{
|
|
|
|
|
Input in;
|
|
|
|
|
size_t number_count, bin_count;
|
|
|
|
|
size_t number_count;
|
|
|
|
|
cin >> number_count;
|
|
|
|
|
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
@ -44,24 +41,22 @@ void find_minmax(const vector<double>& numbers, double& min, double& max)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
vector<double> make_histogram(const vector<double> &numbers, size_t bin_count)
|
|
|
|
|
{
|
|
|
|
|
Input in = input_data();
|
|
|
|
|
double min = numbers[0];
|
|
|
|
|
double max = numbers[0];
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
double bin_size = (max - min) / bin_count;
|
|
|
|
|
vector<double>bins(bin_count);
|
|
|
|
|
|
|
|
|
|
vector<double>bins(in.bin_count);
|
|
|
|
|
|
|
|
|
|
double min, max;
|
|
|
|
|
find_minmax(in.numbers, min, max);
|
|
|
|
|
|
|
|
|
|
double bin_size = (max - min) / in.bin_count;
|
|
|
|
|
for (size_t i = 0; i < in.numbers.size(); i++)
|
|
|
|
|
for (size_t i = 0; i < numbers.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (size_t j = 0; (j < in.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 ((lo <= in.numbers[i]) && (in.numbers[i] < hi))
|
|
|
|
|
if ((lo <= numbers[i]) && (numbers[i] < hi))
|
|
|
|
|
{
|
|
|
|
|
bins[j]++;
|
|
|
|
|
found = true;
|
|
|
|
@ -69,12 +64,11 @@ int main()
|
|
|
|
|
}
|
|
|
|
|
if (!found)
|
|
|
|
|
{
|
|
|
|
|
bins[in.bin_count - 1]++;
|
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double b;
|
|
|
|
|
for (size_t i = 0; i < in.bin_count-1; i++)
|
|
|
|
|
for (size_t i = 0; i < bin_count-1; i++)
|
|
|
|
|
{
|
|
|
|
|
if (bins[i] > bins[i+1])
|
|
|
|
|
{
|
|
|
|
@ -83,8 +77,15 @@ int main()
|
|
|
|
|
bins[i + 1] = b;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bins;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void show_histogram_text(const vector <double> &bins)
|
|
|
|
|
{
|
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
|
const size_t MAX_STAR = SCREEN_WIDTH - 3 - 1;
|
|
|
|
|
size_t max_star_search = bins[-1];
|
|
|
|
|
|
|
|
|
|
size_t max_star_search = bins[-1]; // поиск наибольшего кол-ва из корзины
|
|
|
|
|
if (max_star_search > MAX_STAR)
|
|
|
|
|
{
|
|
|
|
|
for (size_t x : bins)
|
|
|
|
@ -126,5 +127,12 @@ int main()
|
|
|
|
|
cout << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
auto in = input_data();
|
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
show_histogram_text(bins);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|