|
|
@ -3,24 +3,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
struct Input {
|
|
|
|
{
|
|
|
|
vector<double> numbers;
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
size_t bin_count{};
|
|
|
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
|
|
|
};
|
|
|
|
size_t number_count, bin_count;
|
|
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
|
|
|
input_data() {
|
|
|
|
|
|
|
|
size_t number_count;
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
cin >> number_count;
|
|
|
|
cin >> number_count;
|
|
|
|
vector<double> numbers(number_count);
|
|
|
|
Input in;
|
|
|
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
for (size_t 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: ";
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
cin >> bin_count;
|
|
|
|
cin >> in.bin_count;
|
|
|
|
vector<size_t> bins(bin_count);
|
|
|
|
return in;
|
|
|
|
double min = numbers[0];
|
|
|
|
}
|
|
|
|
double max = numbers[0];
|
|
|
|
|
|
|
|
for (double x : numbers)
|
|
|
|
int main()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
|
|
|
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
|
|
|
|
|
|
|
Input in = input_data();
|
|
|
|
|
|
|
|
vector<size_t> bins(in.bin_count);
|
|
|
|
|
|
|
|
double min = in.numbers[0];
|
|
|
|
|
|
|
|
double max = in.numbers[0];
|
|
|
|
|
|
|
|
for (double x : in.numbers)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (x < min)
|
|
|
|
if (x < min)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -31,15 +43,15 @@ int main()
|
|
|
|
max = x;
|
|
|
|
max = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto bin_size = (max - min)/bin_count;
|
|
|
|
auto bin_size = (max - min)/in.bin_count;
|
|
|
|
for (size_t i = 0; i < number_count; i++)
|
|
|
|
for (double number : in.numbers)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
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 lo = min + j * bin_size;
|
|
|
|
auto hi = min + (j + 1) * bin_size;
|
|
|
|
auto hi = min + (j + 1) * bin_size;
|
|
|
|
if ((lo <= numbers[i]) && (numbers[i] < hi))
|
|
|
|
if ((lo <= number) && (number < hi))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bins[j]++;
|
|
|
|
bins[j]++;
|
|
|
|
found = true;
|
|
|
|
found = true;
|
|
|
@ -47,11 +59,11 @@ int main()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
bins[in.bin_count - 1]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
size_t max_count = 0;
|
|
|
|
size_t max_count = 0;
|
|
|
|
for (size_t s = 0; s < bin_count; s++) {
|
|
|
|
for (size_t s = 0; s < in.bin_count; s++) {
|
|
|
|
if (bins[s] > max_count)
|
|
|
|
if (bins[s] > max_count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
max_count = bins[s];
|
|
|
|
max_count = bins[s];
|
|
|
|