Сommit
063383196f
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="lab_01" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/lab_01" 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/lab_01" 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,49 @@
|
|||||||
|
#include <math.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <conio.h>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
size_t numbersCount;
|
||||||
|
cerr << "Numbers count ==>"; cin >> numbersCount;
|
||||||
|
vector<size_t> 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<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 ((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;
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче