|
|
|
@ -8,73 +8,116 @@ using namespace std;
|
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
size_t numbersCount;
|
|
|
|
|
cerr << "Number count ==>"; cin >> numbersCount;
|
|
|
|
|
vector<double> numbers(numbersCount);
|
|
|
|
|
size_t binCount;
|
|
|
|
|
bool running;
|
|
|
|
|
int res;
|
|
|
|
|
running =true;
|
|
|
|
|
res = 0;
|
|
|
|
|
size_t i, j, min, max;
|
|
|
|
|
cerr << "Numbers ==>";
|
|
|
|
|
for (i = 0; i < numbersCount; i++) {
|
|
|
|
|
cin >> numbers[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (running)
|
|
|
|
|
{
|
|
|
|
|
cerr << "Bin count ==>"; cin >> binCount;
|
|
|
|
|
vector<size_t> bins(binCount);
|
|
|
|
|
min = numbers[0];
|
|
|
|
|
struct Input
|
|
|
|
|
{
|
|
|
|
|
vector<double> numbers;
|
|
|
|
|
size_t bin_count{};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
input_data(){
|
|
|
|
|
cerr << "Input numbers count: ";
|
|
|
|
|
size_t number_count;
|
|
|
|
|
cin >> number_count;
|
|
|
|
|
Input in;
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
|
cerr << "Input numbers: ";
|
|
|
|
|
for (size_t i = 0; i < number_count; i++)
|
|
|
|
|
{
|
|
|
|
|
cin >> in.numbers[i];
|
|
|
|
|
}
|
|
|
|
|
cerr << "Input bin count: ";
|
|
|
|
|
cin >> in.bin_count;
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
find_minmax(vector<double> numbers, double &min, double &max)
|
|
|
|
|
{
|
|
|
|
|
min = numbers[0];
|
|
|
|
|
max = numbers[0];
|
|
|
|
|
for (i = 1; i < numbersCount; i++) {
|
|
|
|
|
for (size_t i = 1; i < numbers.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
if (min > numbers[i])
|
|
|
|
|
min = numbers[i];
|
|
|
|
|
if (max < numbers[i])
|
|
|
|
|
max = numbers[i];
|
|
|
|
|
}
|
|
|
|
|
double binSize = (max - min) / (float) binCount;
|
|
|
|
|
for (i = 0; i < numbersCount; i++) {
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vector <size_t> make_histogramm(vector<double>numbers, size_t bin_count)
|
|
|
|
|
{
|
|
|
|
|
double min, max;
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
double binSize = (max - min) / bin_count;
|
|
|
|
|
vector<size_t> bins(bin_count);
|
|
|
|
|
for (size_t i = 0; i < numbers.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (j = 0; (j < binCount - 1) && !found; j++) {
|
|
|
|
|
for (size_t j = 0; (j <= bin_count - 1) && !found; j++)
|
|
|
|
|
{
|
|
|
|
|
auto lo = min + j * binSize;
|
|
|
|
|
auto hi = min + (j + 1) * binSize;
|
|
|
|
|
if ((lo <= numbers[i]) && (numbers[i] < hi)) {
|
|
|
|
|
if ((lo <= numbers[i]) && (numbers[i] < hi))
|
|
|
|
|
{
|
|
|
|
|
bins[j]++;
|
|
|
|
|
found = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found)
|
|
|
|
|
bins[binCount - 1]++;
|
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
|
}
|
|
|
|
|
size_t max_count = 0;
|
|
|
|
|
for (i = 0; i < binCount; i++) {
|
|
|
|
|
size_t max_count = bins[0];
|
|
|
|
|
for (size_t i = 0; i < bin_count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (max_count < bins[i])
|
|
|
|
|
max_count = bins[i];
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < binCount; i++) {
|
|
|
|
|
if (bins[i] < 100)
|
|
|
|
|
cout << " ";
|
|
|
|
|
if (bins[i] < 10)
|
|
|
|
|
cout << " ";
|
|
|
|
|
cout << bins[i];
|
|
|
|
|
cout << "|";
|
|
|
|
|
size_t count = bins[i];
|
|
|
|
|
size_t height = 76 * (static_cast<double>(count) / max_count);
|
|
|
|
|
for (j = 0; j < bins[i]; j++){
|
|
|
|
|
if (j < height) //3 ýòàï
|
|
|
|
|
cout << "*";
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
cout << endl;
|
|
|
|
|
}
|
|
|
|
|
cout << "R u satisfied? " << "1)yeeeeeesss 2)nooooooooo" << endl;
|
|
|
|
|
cin >> res;
|
|
|
|
|
if (res == 1)
|
|
|
|
|
running = false;
|
|
|
|
|
if (max_count > 76) {
|
|
|
|
|
for (size_t i = 0; i < bin_count; i++) {
|
|
|
|
|
int count = bins[i];
|
|
|
|
|
size_t height = 76 * (static_cast<double>(count) / max_count);
|
|
|
|
|
bins[i] = height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bins;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void show_histogramm(vector<size_t>bins)
|
|
|
|
|
{
|
|
|
|
|
for (size_t i = 0; i < bins.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
cout << bins[i] << "|";
|
|
|
|
|
for (size_t j = 0; j < bins[i]; j++)
|
|
|
|
|
cout << "*";
|
|
|
|
|
cout << endl;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
/*bool running;
|
|
|
|
|
int res;
|
|
|
|
|
running =true;
|
|
|
|
|
res = 0;*/
|
|
|
|
|
Input in = input_data();
|
|
|
|
|
|
|
|
|
|
auto bins = make_histogramm(in.numbers, in.bin_count);
|
|
|
|
|
|
|
|
|
|
show_histogramm(bins);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|