commit fe1d6fae432da1f8f5d56f0b2694320cad02b02a Author: Artyom (StepanovAV) Date: Sat Apr 20 13:45:36 2024 +0300 build: добавлены файлы проекта и исходного кода diff --git a/Lab1.cbp b/Lab1.cbp new file mode 100644 index 0000000..c725d43 --- /dev/null +++ b/Lab1.cbp @@ -0,0 +1,40 @@ + + + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e9149cb --- /dev/null +++ b/main.cpp @@ -0,0 +1,74 @@ +#include +#include + +using namespace std; + +const size_t SCREEN_WIDTH = 80; +const size_t MAX_LENGTH = SCREEN_WIDTH - 3 - 1; + +int main() { + int number_count, bin_count, i, j; + cerr << "Enter number count:" << endl; + cin >> number_count; + vector numbers(number_count); + cerr << "Enter numbers:" << endl; + for (i = 0;i < number_count; i++) { + cin >> numbers[i]; + } + auto min = numbers[0]; + auto max = numbers[0]; + for (auto x : numbers) { + if (x < min) { + min = x; + } + else if (x > max) { + max = x; + } + } + cerr << "Enter bin count:" << endl; + cin >> bin_count; + double bin_size = (max - min) / bin_count; + vector bins(bin_count); + for (i = 0; i < number_count; i++) { + bool found = false; + for (j = 0; (j < bin_count - 1) && !found ; j++) { + if ((min + j * bin_size <= numbers[i]) && (numbers[i] < min + (j + 1) * bin_size)) { + bins[j] += 1; + found = true; + } + } + if (!found) bins[bin_count - 1]++; + } + auto max_count = bins[0]; + for (auto x : bins) { + if (x > max_count) { + max_count = x; + } + } + for (i = 0; i < bin_count; i++) { + j = 100; + while (bins[i] < j) { + cout << " "; + j /= 10; + } + cout << bins[i] << "|"; + if (max_count > MAX_LENGTH) { + auto count = bins[i]; + size_t height = MAX_LENGTH * (static_cast(count) / max_count); + j = 0; + while (j < height) { + cout << "*"; + j++; + } + } + else { + j = 0; + while (j < bins[i]) { + cout << "*"; + j++; + } + } + cout << endl; + } + return 0; +}