Родитель
f024cc7c60
Сommit
4c271d1451
@ -0,0 +1,120 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
size_t number_count;
|
||||||
|
cerr<<"Kol-vo chisel -> ";
|
||||||
|
cin>>number_count;
|
||||||
|
|
||||||
|
|
||||||
|
vector <double> numbers(number_count);
|
||||||
|
|
||||||
|
cerr<<"Vvedite chisla:";
|
||||||
|
cout<<endl;
|
||||||
|
for(size_t i=0; i<number_count; i++)
|
||||||
|
{
|
||||||
|
cin>>numbers[i];
|
||||||
|
//cout<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t bin_count;
|
||||||
|
cerr<<"vvedite kolvo bins -> ";
|
||||||
|
cin>>bin_count;
|
||||||
|
vector<size_t> bins(bin_count);
|
||||||
|
|
||||||
|
|
||||||
|
double min = numbers[0];
|
||||||
|
double max = numbers[0];
|
||||||
|
for (double x : numbers)
|
||||||
|
{
|
||||||
|
if (x < min)
|
||||||
|
{
|
||||||
|
min = x;
|
||||||
|
}
|
||||||
|
else if (x > max)
|
||||||
|
{
|
||||||
|
max = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double bin_size = (max-min)/bin_count;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < number_count; i++)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
|
||||||
|
{
|
||||||
|
auto lo = min + j * bin_size;
|
||||||
|
auto hi = min + (j + 1) * bin_size;
|
||||||
|
if ((lo <= numbers[i]) && (numbers[i] < hi))
|
||||||
|
{
|
||||||
|
bins[j]++;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
bins[bin_count - 1]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t max_count=0;
|
||||||
|
for (size_t i =0; i<bin_count; i++)
|
||||||
|
{
|
||||||
|
if (max_count <bins[i])
|
||||||
|
{
|
||||||
|
max_count=bins[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
float procent;
|
||||||
|
for(size_t i=0; i<bin_count; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int procent =((float)bins[i] / number_count)*100;
|
||||||
|
|
||||||
|
|
||||||
|
if (procent<10)
|
||||||
|
{
|
||||||
|
cout<<" "<<procent<<"% | ";
|
||||||
|
}
|
||||||
|
if ((procent<100)&&(procent>=10))
|
||||||
|
{
|
||||||
|
cout<<" "<<procent<<"% | ";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
size_t height = 0;
|
||||||
|
|
||||||
|
if (max_count>76)//ìàøòàáèðîâàíèå
|
||||||
|
{
|
||||||
|
size_t height = 76 * (static_cast<double>(bins[i]) / max_count);
|
||||||
|
for(size_t j=0; j<=height; j++)
|
||||||
|
{
|
||||||
|
|
||||||
|
cout<<"*";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(size_t j=0; j<=bins[i]-1; j++)
|
||||||
|
{
|
||||||
|
|
||||||
|
cout<<"*";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
cout<<endl;
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче