Сравнить коммиты
2 Коммитов
472050717e
...
686c2de87a
| Автор | SHA1 | Дата | |
|---|---|---|---|
| 686c2de87a | |||
| ce44f427ba |
70
main.cpp
70
main.cpp
@@ -2,11 +2,48 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
struct Input
|
||||||
|
{
|
||||||
|
vector<double> numbers;
|
||||||
|
size_t bin_count{};
|
||||||
|
};
|
||||||
|
Input input_data()
|
||||||
|
{
|
||||||
|
Input in;
|
||||||
|
size_t number_count;
|
||||||
|
cerr << "Enter number count: ";
|
||||||
|
cin >> number_count;
|
||||||
|
in.numbers.resize(number_count);
|
||||||
|
cerr << "Enter numbers: ";
|
||||||
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
|
cin >> in.numbers[i];
|
||||||
|
}
|
||||||
|
size_t bin_count;
|
||||||
|
cerr << "Enter bin count: ";
|
||||||
|
cin >> in.bin_count;
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
void find_minmax(const vector<double>& numbers, double& min, double& max) {
|
||||||
|
min = numbers[0];
|
||||||
|
max = numbers[0];
|
||||||
|
for (double x : numbers)
|
||||||
|
{
|
||||||
|
if (x < min)
|
||||||
|
{
|
||||||
|
min = x;
|
||||||
|
}
|
||||||
|
else if (x > max)
|
||||||
|
{
|
||||||
|
max = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
const size_t SCREEN_WIDTH = 80;
|
const size_t SCREEN_WIDTH = 80;
|
||||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||||
|
Input in = input_data();
|
||||||
|
//
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
cerr << "Enter number count: ";
|
cerr << "Enter number count: ";
|
||||||
cin >> number_count;
|
cin >> number_count;
|
||||||
@@ -21,22 +58,23 @@ int main()
|
|||||||
size_t bin_count;
|
size_t bin_count;
|
||||||
cerr << "Enter bin count: ";
|
cerr << "Enter bin count: ";
|
||||||
cin >> bin_count;
|
cin >> bin_count;
|
||||||
|
//
|
||||||
vector<size_t> bins(bin_count, 0);
|
vector<size_t> bins(bin_count, 0);
|
||||||
|
double min, max;
|
||||||
double min = numbers[0];
|
find_minmax(in.numbers, min, max);
|
||||||
double max = numbers[0];
|
// double min = numbers[0];
|
||||||
for (double x : numbers)
|
// double max = numbers[0];
|
||||||
{
|
//for (double x : numbers)
|
||||||
if (x < min)
|
// {
|
||||||
{
|
// if (x < min)
|
||||||
min = x;
|
// {
|
||||||
}
|
// min = x;
|
||||||
else if (x > max)
|
// }
|
||||||
{
|
// else if (x > max)
|
||||||
max = x;
|
// {
|
||||||
}
|
// max = x;
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
double bin_size = (max - min) / bin_count;
|
double bin_size = (max - min) / bin_count;
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user