Сommit
42c1ece97f
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="Lab34" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/Lab1" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Debug/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-g" />
|
||||||
|
</Compiler>
|
||||||
|
</Target>
|
||||||
|
<Target title="Release">
|
||||||
|
<Option output="bin/Release/Lab1" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Release/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-O2" />
|
||||||
|
</Compiler>
|
||||||
|
<Linker>
|
||||||
|
<Add option="-s" />
|
||||||
|
</Linker>
|
||||||
|
</Target>
|
||||||
|
</Build>
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-Wall" />
|
||||||
|
<Add option="-fexceptions" />
|
||||||
|
</Compiler>
|
||||||
|
<Unit filename="main.cpp" />
|
||||||
|
<Extensions>
|
||||||
|
<lib_finder disable_auto="1" />
|
||||||
|
</Extensions>
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
@ -0,0 +1,74 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<double> 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<size_t> 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<double>(count) / max_count);
|
||||||
|
j = 0;
|
||||||
|
while (j < height) {
|
||||||
|
cout << "*";
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
j = 0;
|
||||||
|
while (j < bins[i]) {
|
||||||
|
cout << "*";
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче