Сommit
14bb76a81b
@ -0,0 +1,80 @@
|
||||
#include <vector>
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
#include <conio.h>
|
||||
#include <fstream>
|
||||
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];
|
||||
max = numbers[0];
|
||||
for (i = 1; i < numbersCount; 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++) {
|
||||
bool found = false;
|
||||
for (j = 0; (j < binCount - 1) && !found; j++) {
|
||||
auto lo = min + j * binSize;
|
||||
auto hi = min + (j + 1) * binSize;
|
||||
if ((lo <= numbers[i]) && (numbers[i] < hi)) {
|
||||
bins[j]++;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
bins[binCount - 1]++;
|
||||
}
|
||||
size_t max_count = 0;
|
||||
for (i = 0; i < binCount; 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;
|
||||
}
|
||||
return 0;
|
||||
}
|
Загрузка…
Ссылка в новой задаче