Родитель
f827c405aa
Сommit
8f0cc94d7b
@ -0,0 +1,101 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
using namespace std;
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
|
||||
int main()
|
||||
{
|
||||
size_t i, j; //ԅ(≖‿≖ԅ)//
|
||||
size_t histo_height;
|
||||
size_t number_count;
|
||||
size_t bin_count;
|
||||
cerr << "Enter number count: ";
|
||||
cin >> number_count;
|
||||
vector<double> numbers(number_count);
|
||||
for (i = 0; i < number_count; i++)
|
||||
{
|
||||
cerr << "Number[" << i << "] is ";
|
||||
cin >> numbers[i];
|
||||
}
|
||||
|
||||
|
||||
double max = numbers[0];
|
||||
double min = numbers[0];
|
||||
for (i = 0; i < number_count; i++)
|
||||
{
|
||||
if (numbers[i] < min)
|
||||
min = numbers[i];
|
||||
|
||||
else if (numbers[i] > max)
|
||||
max = numbers[i];
|
||||
}
|
||||
cerr << "Enter bin count: ";
|
||||
cin >> bin_count;
|
||||
|
||||
cerr << "Enter histo height: ";
|
||||
cin >> histo_height;
|
||||
size_t table_height = histo_height / bin_count;
|
||||
|
||||
vector<size_t> bins(bin_count);
|
||||
double bin_size = (max - min) / bin_count;
|
||||
size_t max_count = 0;
|
||||
for (i = 0; i < number_count; i++)
|
||||
{
|
||||
bool found = false;
|
||||
for (j = 0; (j < bin_count - 1) && !found; j++)
|
||||
{
|
||||
double lo = min + j * bin_size;
|
||||
double hi = min + (j + 1) * bin_size;
|
||||
if ((lo <= numbers[i]) && (numbers[i] < hi))
|
||||
{
|
||||
bins[j]++;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
bins[bin_count - 1]++;
|
||||
}
|
||||
for (size_t i = 0; i < bin_count; i++)
|
||||
{
|
||||
if (bins[i] > max_count)
|
||||
max_count = bins[i];
|
||||
|
||||
}
|
||||
}
|
||||
size_t height = 0;
|
||||
for (i = 0; i < bin_count; i++)
|
||||
{
|
||||
|
||||
for (size_t a = 0; a < table_height; a++)
|
||||
{
|
||||
if (bins[i] < 100)
|
||||
cout << " ";
|
||||
if (bins[i] < 10)
|
||||
cout << " ";
|
||||
cout << bins[i] << "|";
|
||||
if (max_count > MAX_ASTERISK)
|
||||
{
|
||||
for (j = 0; j < (height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count)); j++)
|
||||
{
|
||||
cout << "*";
|
||||
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = 0; j < bins[i]; j++)
|
||||
{
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче