|
|
|
@ -7,24 +7,28 @@
|
|
|
|
|
#define PREFIX 4
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
struct Input {
|
|
|
|
|
vector<double> numbers;
|
|
|
|
|
size_t bin_count{};
|
|
|
|
|
};
|
|
|
|
|
Input input_data()
|
|
|
|
|
{
|
|
|
|
|
Input in;
|
|
|
|
|
int number_count;
|
|
|
|
|
int bin_count;
|
|
|
|
|
//Ввод данных
|
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
|
cin >> number_count;
|
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
|
cin >> bin_count;
|
|
|
|
|
vector<double> numbers(number_count);
|
|
|
|
|
vector<int> bins(bin_count);
|
|
|
|
|
for (int i = 0; i < number_count; i++)
|
|
|
|
|
{
|
|
|
|
|
cin >> numbers[i];
|
|
|
|
|
cin >> in.bin_count;
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
|
for (size_t i = 0; i < number_count; i++) {
|
|
|
|
|
cin >> in.numbers[i];
|
|
|
|
|
}
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
//Находим минимальное и максимальное значение
|
|
|
|
|
double min = numbers[0];
|
|
|
|
|
double max = numbers[0];
|
|
|
|
|
|
|
|
|
|
void find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|
|
|
|
min = numbers[0];
|
|
|
|
|
max = numbers[0];
|
|
|
|
|
for (double x : numbers)
|
|
|
|
|
{
|
|
|
|
|
if (x < min)
|
|
|
|
@ -36,7 +40,14 @@ int main()
|
|
|
|
|
max = x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//Вычисляем гистограмму
|
|
|
|
|
}
|
|
|
|
|
vector<double> make_histogram(const vector<double>& numbers, size_t bin_count)
|
|
|
|
|
{
|
|
|
|
|
vector <double> bins;
|
|
|
|
|
double min, max;
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
int number_count = numbers.size();
|
|
|
|
|
bins.resize(bin_count);
|
|
|
|
|
double bin_size = (max - min) / bin_count;
|
|
|
|
|
for (int i = 0; i < number_count; i++)
|
|
|
|
|
{
|
|
|
|
@ -57,6 +68,11 @@ int main()
|
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bins;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void show_histogram_text(const vector<double>& bins)
|
|
|
|
|
{
|
|
|
|
|
//Находим максимум значений корзин
|
|
|
|
|
int max_count = bins[0];
|
|
|
|
|
for (int x : bins)
|
|
|
|
@ -73,10 +89,11 @@ int main()
|
|
|
|
|
{
|
|
|
|
|
K = 1;
|
|
|
|
|
}
|
|
|
|
|
//K = 0; // принудительное отключение масштабирования для 1 и 2
|
|
|
|
|
|
|
|
|
|
//Строим гистограмму
|
|
|
|
|
int cnt;
|
|
|
|
|
for (int i = 0; i < bin_count; i++)
|
|
|
|
|
int bin_sz = bins.size();
|
|
|
|
|
for (int i = 0; i < bin_sz; i++)
|
|
|
|
|
{
|
|
|
|
|
cout.width(3);
|
|
|
|
|
cout.fill(' ');
|
|
|
|
@ -94,6 +111,15 @@ int main()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
auto in = input_data();
|
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
show_histogram_text(bins);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
|
|
|
|
|
// Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
|
|
|
|
|
|
|
|
|
|