Сommit
954eb17483
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="1" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/1" 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/1" 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,96 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
const size_t SCREEN_WIDTH = 80;
|
||||||
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 6 - 1;
|
||||||
|
size_t bin_count, counts;
|
||||||
|
cerr << "Enter counts:";
|
||||||
|
cin >> counts;
|
||||||
|
|
||||||
|
vector <double> numbers(counts);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < counts; i++){
|
||||||
|
cerr << "Enter array "<< i <<" number:";
|
||||||
|
cin >> numbers[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
cerr << "Enter bin_count:";
|
||||||
|
cin >> bin_count;
|
||||||
|
|
||||||
|
double minN = numbers[0], maxN = numbers[0];
|
||||||
|
|
||||||
|
for (double x: numbers){
|
||||||
|
if (minN > x){
|
||||||
|
minN = x;
|
||||||
|
}
|
||||||
|
if (maxN < x){
|
||||||
|
maxN = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double diff = (maxN - minN) / bin_count;
|
||||||
|
|
||||||
|
vector <size_t> bins(bin_count);
|
||||||
|
|
||||||
|
size_t max_count = 0;
|
||||||
|
for (size_t i = 0; i < counts; i++){
|
||||||
|
bool found = false;
|
||||||
|
for (size_t j = 0;(j < bin_count - 1) && !found; j++){
|
||||||
|
auto lo = minN + j * diff;
|
||||||
|
auto hi = minN + (j + 1) * diff;
|
||||||
|
if ((lo <= numbers[i]) && (hi > numbers[i])){
|
||||||
|
bins[j]++;
|
||||||
|
if (bins[j] > max_count){
|
||||||
|
max_count = bins[j];
|
||||||
|
}
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!found){
|
||||||
|
bins[bin_count - 1]++;
|
||||||
|
if (bins[bin_count - 1] > max_count){
|
||||||
|
max_count = bins[bin_count - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool scaling = false;
|
||||||
|
|
||||||
|
if (max_count > MAX_ASTERISK){
|
||||||
|
scaling = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < bin_count; i++){
|
||||||
|
cout << " ";
|
||||||
|
if (bins[i] < 100){
|
||||||
|
cout << " ";
|
||||||
|
}
|
||||||
|
if (bins[i] < 10){
|
||||||
|
cout << " ";
|
||||||
|
}
|
||||||
|
cout << bins[i] << "|";
|
||||||
|
|
||||||
|
size_t number_of_stars = bins[i];
|
||||||
|
|
||||||
|
if (scaling){
|
||||||
|
if (bins[i] == max_count){
|
||||||
|
number_of_stars = MAX_ASTERISK * 1.0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
number_of_stars = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t j = 0; j < number_of_stars; j++){
|
||||||
|
cout << "*";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
if (i < bin_count - 1){
|
||||||
|
cout << minN + (i + 1) * diff << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче