|
|
|
@ -3,35 +3,55 @@
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
|
|
|
|
struct Input {
|
|
|
|
|
vector<double> numbers;
|
|
|
|
|
size_t bin_count{};
|
|
|
|
|
};
|
|
|
|
|
Input
|
|
|
|
|
input_data(){
|
|
|
|
|
size_t number_count, bin_count;
|
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
|
cin >> number_count; //Êîë-âî ÷èñåë
|
|
|
|
|
Input in;
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
|
|
|
|
|
|
size_t number_count, bin_count, max_bin, height;
|
|
|
|
|
double maxx, minn;
|
|
|
|
|
cerr << "Enter number count: "; cin >> number_count; //Êîë-âî ÷èñåë
|
|
|
|
|
|
|
|
|
|
vector <double> numbers(number_count);
|
|
|
|
|
for (int i = 0; i < number_count; i++)
|
|
|
|
|
for (size_t i = 0; i < number_count; i++)
|
|
|
|
|
{
|
|
|
|
|
cerr << "Enter Num[" << i << "]: "; cin >> numbers[i]; //Ââîä ÷èñåë
|
|
|
|
|
cerr << "Enter Num[" << i << "]: ";
|
|
|
|
|
cin >> in.numbers[i]; //Ââîä ÷èñåë
|
|
|
|
|
}
|
|
|
|
|
cerr << "Enter bin count: "; cin >> bin_count; //Êîë-âî êîðçèí
|
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
|
cin >> in.bin_count; //Êîë-âî êîðçèí
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vector <size_t> bins(bin_count);
|
|
|
|
|
maxx = numbers[0]; minn = numbers[1];
|
|
|
|
|
for (size_t i = 0; i < number_count; i++)
|
|
|
|
|
void find_minmax(const vector<double> &numbers, double &min, double &max)
|
|
|
|
|
{
|
|
|
|
|
max = numbers[0];
|
|
|
|
|
min = numbers[1];
|
|
|
|
|
for (double x: numbers)
|
|
|
|
|
{
|
|
|
|
|
if (maxx < numbers[i])
|
|
|
|
|
maxx = numbers[i];
|
|
|
|
|
if (minn > numbers[i])
|
|
|
|
|
minn = numbers[i];
|
|
|
|
|
if (x < min)
|
|
|
|
|
{
|
|
|
|
|
min = x;
|
|
|
|
|
}
|
|
|
|
|
else if (x > max)
|
|
|
|
|
{
|
|
|
|
|
max = x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double bin_size = (maxx - minn) / bin_count;
|
|
|
|
|
vector<size_t> make_histogram (vector<double> numbers, size_t bin_count)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < number_count; i++)
|
|
|
|
|
double minn;
|
|
|
|
|
double maxx;
|
|
|
|
|
find_minmax (numbers, minn, maxx);
|
|
|
|
|
double bin_size = (maxx - minn) / bin_count;
|
|
|
|
|
vector<size_t> bins(bin_count);
|
|
|
|
|
for (size_t i = 0; i < numbers.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
|
|
|
|
@ -49,12 +69,21 @@ int main()
|
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bins;
|
|
|
|
|
}
|
|
|
|
|
void show_histogram_text(vector<size_t> bins, size_t bin_count)
|
|
|
|
|
{
|
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
|
|
|
|
double max_bin;
|
|
|
|
|
size_t height;
|
|
|
|
|
max_bin = bins[0];
|
|
|
|
|
height = bins[0];
|
|
|
|
|
for (size_t i = 0; i < bin_count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (bins[i] > max_bin)
|
|
|
|
|
if (bins[i] > max_bin){
|
|
|
|
|
max_bin = bins[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool flag = false;
|
|
|
|
@ -82,8 +111,14 @@ int main()
|
|
|
|
|
cout << "*";
|
|
|
|
|
}
|
|
|
|
|
cout << endl;
|
|
|
|
|
if ((bin_count - i) != 1)
|
|
|
|
|
cout << minn + bin_size * (i+1) << 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;
|
|
|
|
|
}
|
|
|
|
|