|
|
|
@ -1,12 +1,18 @@
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
struct Input
|
|
|
|
|
{
|
|
|
|
|
vector<double> numbers;
|
|
|
|
|
size_t bin_count{};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
Input input_data()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
size_t number_count, bin_count;
|
|
|
|
@ -14,25 +20,28 @@ int main()
|
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
|
cin >> number_count;
|
|
|
|
|
|
|
|
|
|
Input in;
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
|
|
|
|
|
|
cerr << "Enter numbers: ";
|
|
|
|
|
|
|
|
|
|
vector<double> numbers(number_count);
|
|
|
|
|
// vector<double> numbers(number_count);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < number_count; i++)
|
|
|
|
|
for (size_t i = 0; i < number_count; i++)
|
|
|
|
|
{
|
|
|
|
|
cin >> numbers[i];
|
|
|
|
|
cin >> in.numbers[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
|
cin >> bin_count;
|
|
|
|
|
cerr << " number of baskets: ";
|
|
|
|
|
cin >> in.bin_count;
|
|
|
|
|
|
|
|
|
|
vector<double> bins(bin_count);
|
|
|
|
|
vector<int> count(number_count);
|
|
|
|
|
vector<double> height(bin_count);
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
int max_count = bins[0];
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
@ -46,32 +55,44 @@ int main()
|
|
|
|
|
max = x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double bin_size = (max - min) / bin_count;
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
Input in = input_data();
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < number_count; i++)
|
|
|
|
|
vector<int> bins(in.bin_count);
|
|
|
|
|
vector<double> height(in.bin_count);
|
|
|
|
|
|
|
|
|
|
int max_count = bins[0];
|
|
|
|
|
double min = in.numbers[0];
|
|
|
|
|
double max = in.numbers[0];
|
|
|
|
|
|
|
|
|
|
find_minmax(in.numbers, min, max);
|
|
|
|
|
|
|
|
|
|
double bin_size = (max - min) / in.bin_count;
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < in.numbers.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
|
|
|
|
|
for (size_t j = 0; (j < in.bin_count - 1) && !found; j++)
|
|
|
|
|
{
|
|
|
|
|
auto lo = min + j * bin_size;
|
|
|
|
|
auto hi = min + (j + 1) * bin_size;
|
|
|
|
|
|
|
|
|
|
if ((lo <= numbers[i]) && (numbers[i] < hi))
|
|
|
|
|
if ((lo <= in.numbers[i]) && (in.numbers[i] < hi))
|
|
|
|
|
{
|
|
|
|
|
bins[j]++;
|
|
|
|
|
count[j]++;
|
|
|
|
|
found = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!found )
|
|
|
|
|
if (!found)
|
|
|
|
|
{
|
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
|
count[bin_count - 1]++;
|
|
|
|
|
bins[in.bin_count - 1]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < bin_count; i++)
|
|
|
|
|
for (int i = 0; i < in.bin_count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (bins[i] > max_count)
|
|
|
|
|
{
|
|
|
|
@ -79,12 +100,17 @@ int main()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < bin_count; i++)
|
|
|
|
|
for (int i = 0; i < in.bin_count; i++)
|
|
|
|
|
{
|
|
|
|
|
height[i] = (MAX_ASTERISK * count[i]) / max_count;
|
|
|
|
|
if (bins[i] > MAX_ASTERISK)
|
|
|
|
|
{
|
|
|
|
|
height[i] = (MAX_ASTERISK * bins[i]) / max_count;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
height[i] = bins[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < bin_count; i++)
|
|
|
|
|
for (int i = 0; i < in.bin_count; i++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (bins[i] < 100)
|
|
|
|
|