VolodinDV 1 год назад
Сommit a68a044912

3
.gitignore поставляемый

@ -0,0 +1,3 @@
/bin
/obj

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="lab1" />
<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>
<Linker>
<Add option="-static-libstdc++" />
<Add option="-static-libgcc" />
<Add option="-static" />
</Linker>
</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,81 @@
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 4;
size_t n,h;
cerr<<"Enter number count ";
cin>>n;
cerr<<"Enter bin count ";
cin>>h;
vector <double> num(n);
vector <size_t> bins(h);
cerr<<"Enter massive elements ";
for (size_t i=0;i<n;i++){
cin>> num[i];
}
double minn = num[0];
double maxx = num[0];
for (double x : num) {
if (x < minn) {
minn = x;
}
else if (x > maxx) {
maxx = x;
}
}
double l=(maxx - minn) / h;
for (size_t i = 0; i < n; i++) {
bool found = false;
for (size_t j = 0; (j < h - 1) && !found; j++) {
auto lo = minn + j * l;
auto hi = minn + (j + 1) * l;
if ((lo <= num[i]) && (num[i] < hi)) {
bins[j]++;
found = true;
}
}
if (!found) {
bins[h - 1]++;
}
}
size_t max_count = bins[0];
for (size_t i = 0; i < h; i++) {
if (bins[i]>max_count) {
max_count = bins[i];
}
}
vector<size_t> height(h);
for (size_t i = 0; i < h; i++) {
if (max_count > MAX_ASTERISK) {
height[i] = round(MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count));
} else {
height[i]=bins[i];
}
}
for (size_t i=0;i<h;i++){
if(bins[i]<1000 && bins[i]>=100){
cout<< bins[i]<< "|";
for (size_t j=0;j<height[i];j++){
cout <<"*";
}
cout << endl;
}
if(bins[i]<100 && bins[i]>=10){
cout<<" "<< bins[i]<< "|";
for (size_t j=0;j<height[i];j++){
cout <<"*";
}
cout << endl;
}
if(bins[i]<10){
cout<<" "<< bins[i]<< "|";
for (size_t j=0;j<height[i];j++){
cout <<"*";
}
cout << endl;
}
}
}
Загрузка…
Отмена
Сохранить