|
|
|
@ -35,19 +35,16 @@ Input input_data()
|
|
|
|
|
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
void find_minmax(const vector<double> &numbers, double &min, double &max)
|
|
|
|
|
{
|
|
|
|
|
min = numbers[0];
|
|
|
|
|
for (double x : numbers)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (x < min)
|
|
|
|
|
{
|
|
|
|
|
min = x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (x > max)
|
|
|
|
|
{
|
|
|
|
|
max = x;
|
|
|
|
@ -55,30 +52,25 @@ void find_minmax(const vector<double> &numbers, double &min, double &max)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
vector<int> make_histogram(const vector<double> &numbers, size_t bin_count)
|
|
|
|
|
{
|
|
|
|
|
Input in = input_data();
|
|
|
|
|
|
|
|
|
|
vector<int> bins(in.bin_count);
|
|
|
|
|
vector<double> height(in.bin_count);
|
|
|
|
|
|
|
|
|
|
vector<int> bins(bin_count);
|
|
|
|
|
int max_count = bins[0];
|
|
|
|
|
double min = in.numbers[0];
|
|
|
|
|
double max = in.numbers[0];
|
|
|
|
|
double min = numbers[0];
|
|
|
|
|
double max = numbers[0];
|
|
|
|
|
|
|
|
|
|
find_minmax(in.numbers, min, max);
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
double bin_size = (max - min) / bin_count;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
@ -87,18 +79,24 @@ int main()
|
|
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
|
{
|
|
|
|
|
bins[in.bin_count - 1]++;
|
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bins;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < in.bin_count; i++)
|
|
|
|
|
|
|
|
|
|
void show_histogram_text(vector<int> &bins, size_t bin_count)
|
|
|
|
|
{
|
|
|
|
|
int max_count = bins[0];
|
|
|
|
|
for (int i = 0; i < bin_count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (bins[i] > max_count)
|
|
|
|
|
{
|
|
|
|
|
max_count = bins[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < in.bin_count; i++)
|
|
|
|
|
vector<double> height(bin_count);
|
|
|
|
|
for (int i = 0; i < bin_count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (bins[i] > MAX_ASTERISK)
|
|
|
|
|
{
|
|
|
|
@ -108,7 +106,7 @@ int main()
|
|
|
|
|
height[i] = bins[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < in.bin_count; i++)
|
|
|
|
|
for (int i = 0; i < bin_count; i++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (bins[i] < 100)
|
|
|
|
@ -129,6 +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, in.bin_count);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|