|
|
|
@ -5,9 +5,10 @@
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
void mmV(vector<double> numbers, double& min, double& max);
|
|
|
|
|
void find_minmax(vector<double> numbers, double& min, double& max);
|
|
|
|
|
size_t maxBin(vector<size_t> bins);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
|
|
|
|
struct Input {
|
|
|
|
@ -17,40 +18,14 @@ struct Input {
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
vector<size_t> bins;
|
|
|
|
|
size_t countOfNumbers;
|
|
|
|
|
size_t maxCount;
|
|
|
|
|
double max;
|
|
|
|
|
double min;
|
|
|
|
|
|
|
|
|
|
numbers.resize(countOfNumbers);
|
|
|
|
|
Input in = input_data();
|
|
|
|
|
vector<size_t> bins = make_histogram(in.numbers,in.bin_count);
|
|
|
|
|
|
|
|
|
|
cerr << endl;
|
|
|
|
|
cerr << "Input bin count:\n";
|
|
|
|
|
cin >> binCount;
|
|
|
|
|
bins.resize(binCount);
|
|
|
|
|
mmV(numbers, min, max);
|
|
|
|
|
double bin_size = (max - min) / binCount;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < countOfNumbers; i++) {
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (size_t j = 0; (j < binCount - 1) && !found; j++) {
|
|
|
|
|
auto lo = min + j * bin_size;
|
|
|
|
|
auto hi = min + (j + 1) * bin_size;
|
|
|
|
|
if ((lo <= numbers[i]) && (hi > numbers[i])) {
|
|
|
|
|
bins[j]++;
|
|
|
|
|
found = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found) {
|
|
|
|
|
bins[binCount - 1]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
maxCount = maxBin(bins);
|
|
|
|
|
size_t count_stars;
|
|
|
|
|
for (int i = 0; i < binCount; i++) {
|
|
|
|
|
for (int i = 0; i < in.bin_count; i++) {
|
|
|
|
|
|
|
|
|
|
if (bins[i] < 100) {
|
|
|
|
|
cout << " ";
|
|
|
|
@ -75,11 +50,11 @@ int main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t maxBin(vector<size_t> bins) { //ëó÷øå áåç ôóíêöèè
|
|
|
|
|
/*size_t maxBin(vector<size_t> bins) {
|
|
|
|
|
size_t max = bins[0];
|
|
|
|
|
for (int i = 1; i < bins.size(); i++) {
|
|
|
|
|
if (max < bins[i]) {
|
|
|
|
@ -87,8 +62,8 @@ size_t maxBin(vector<size_t> bins) { //
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return max;
|
|
|
|
|
}
|
|
|
|
|
void mmV(vector<double> numbers, double& min, double& max) { //ñêàçàë ñäåëàòü áåç ôóíêöèè
|
|
|
|
|
}*/
|
|
|
|
|
void find_minmax(vector<double> numbers, double& min, double& max) {
|
|
|
|
|
min = numbers[0];
|
|
|
|
|
max = numbers[0];
|
|
|
|
|
for (double number : numbers) {
|
|
|
|
@ -104,17 +79,45 @@ void mmV(vector<double> numbers, double& min, double& max) { //
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Input input_data() {
|
|
|
|
|
cerr << "Input your count of numbers:\n";
|
|
|
|
|
Input input_struct;
|
|
|
|
|
size_t countOfNumbers;
|
|
|
|
|
cerr << "Input your count of numbers:\n";
|
|
|
|
|
cin >> countOfNumbers;
|
|
|
|
|
cerr << "Input numbers:\n";
|
|
|
|
|
input_struct.numbers.resize(countOfNumbers);
|
|
|
|
|
|
|
|
|
|
cerr << "Input bin count:\n";
|
|
|
|
|
cin >> input_struct.bin_count;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < countOfNumbers; i++) {
|
|
|
|
|
cerr << i << endl;
|
|
|
|
|
cin >> numbers[i];
|
|
|
|
|
cin >> input_struct.numbers[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cerr << endl;
|
|
|
|
|
return input_struct;
|
|
|
|
|
}
|
|
|
|
|
//var15 áåç ìàñøòàáèðîâàíèÿ çàùèòà
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector<size_t> make_histogram(vector<double> numbers, size_t bin_count)
|
|
|
|
|
{
|
|
|
|
|
double max;
|
|
|
|
|
double min;
|
|
|
|
|
vector<size_t> bins;
|
|
|
|
|
bins.resize(bin_count);
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
double bin_size = (max - min) / 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++) {
|
|
|
|
|
auto lo = min + j * bin_size;
|
|
|
|
|
auto hi = min + (j + 1) * bin_size;
|
|
|
|
|
if ((lo <= numbers[i]) && (hi > numbers[i])) {
|
|
|
|
|
bins[j]++;
|
|
|
|
|
found = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found) {
|
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bins;
|
|
|
|
|
}
|
|
|
|
|