commit 063383196f2a8dc5b930e905184acbc17305c346 Author: MakhnovGA Date: Wed Apr 19 21:57:25 2023 +0300 git: создание репозитария diff --git a/lab_01.cbp b/lab_01.cbp new file mode 100644 index 0000000..60802b2 --- /dev/null +++ b/lab_01.cbp @@ -0,0 +1,40 @@ + + + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..75b6324 --- /dev/null +++ b/main.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +using namespace std; + +int main() { + size_t numbersCount; + cerr << "Numbers count ==>"; cin >> numbersCount; + vector numbers(numbersCount); + + size_t i, j, min, max; + cerr << "Numbers ==>"; + for (i = 0; i < numbersCount; i++) + cin >> numbers[i]; + size_t binCount; + cerr << "Bin count ==>"; cin >> binCount; + vector 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 ((numbers[i] >= lo) && (numbers[i] < hi)) { + bins[j]++; + found = true; + } + } + if (!found) + bins[binCount - 1]++; + } + for (i = 0; i < binCount; i++) { + cout << bins[i] << "|"; + for (j = 0; j < bins[i]; j++) + cout << "*"; + cout << endl; + } + return 0; +}