|
|
|
@ -2,162 +2,88 @@
|
|
|
|
|
#include <vector>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
struct Input
|
|
|
|
|
{
|
|
|
|
|
vector<double> numbers;
|
|
|
|
|
size_t bin_count;
|
|
|
|
|
};
|
|
|
|
|
Input
|
|
|
|
|
input_data()
|
|
|
|
|
{
|
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
|
|
|
|
unsigned int n;
|
|
|
|
|
size_t m;
|
|
|
|
|
int i;
|
|
|
|
|
char sim;
|
|
|
|
|
float lo,hi,dif, maxxs,minxs;
|
|
|
|
|
cerr<< "enter amount of numbers";
|
|
|
|
|
cin>>n;
|
|
|
|
|
vector <float> xs(n);
|
|
|
|
|
cerr<<"let's introduse array";
|
|
|
|
|
for(i=0; i < n; i++)
|
|
|
|
|
size_t number_count;
|
|
|
|
|
cin >> number_count;
|
|
|
|
|
Input in;
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
|
for (size_t i = 0; i < number_count; i++)
|
|
|
|
|
{
|
|
|
|
|
cin>> xs[i];
|
|
|
|
|
cin >> in.numbers[i];
|
|
|
|
|
}
|
|
|
|
|
cerr << "enter amount of intervals";
|
|
|
|
|
cin >> m;
|
|
|
|
|
vector <size_t> b(m);
|
|
|
|
|
maxxs = minxs = xs[0];
|
|
|
|
|
for (i=0; i < n; i++)
|
|
|
|
|
size_t bin_count;
|
|
|
|
|
cin >> bin_count;
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
find_minmax(const vector<double>& numbers, double& min, double& max)
|
|
|
|
|
{
|
|
|
|
|
min = numbers[0];
|
|
|
|
|
max = numbers[0];
|
|
|
|
|
for ( size_t i=0; i < numbers.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
if (xs[i] > maxxs) maxxs=xs[i];
|
|
|
|
|
if (xs[i] < minxs) minxs=xs[i];
|
|
|
|
|
if (numbers[i] > max) max=numbers[i];
|
|
|
|
|
if (numbers[i] < min) min=numbers[i];
|
|
|
|
|
}
|
|
|
|
|
dif=(maxxs - minxs)/m;
|
|
|
|
|
for(int i=0; i < n; i++)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::vector<long long unsigned int>
|
|
|
|
|
make_histogram(const vector<double>& numbers,size_t bin_count)
|
|
|
|
|
{
|
|
|
|
|
float lo,hi,dif;
|
|
|
|
|
double min, max;
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
vector <size_t> bins(bin_count) ;
|
|
|
|
|
dif=(max - min)/bin_count;
|
|
|
|
|
for(int i=0; i < numbers.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (int j=0; (j < m-1)&&!found; j++)
|
|
|
|
|
for (int j=0; (j < bin_count-1)&&!found; j++)
|
|
|
|
|
{
|
|
|
|
|
lo= minxs + j*dif;
|
|
|
|
|
hi= minxs + (j+1)*dif;
|
|
|
|
|
if ((lo <= xs[i]) && (xs[i] <hi ))
|
|
|
|
|
lo= min + j*dif;
|
|
|
|
|
hi= min + (j+1)*dif;
|
|
|
|
|
if ((lo <= numbers[i]) && (numbers[i] <hi ))
|
|
|
|
|
{
|
|
|
|
|
b[j]++;
|
|
|
|
|
bins[j]++;
|
|
|
|
|
found = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found)
|
|
|
|
|
{
|
|
|
|
|
b[m - 1]++;
|
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
size_t bmax,height,hem,hep;
|
|
|
|
|
int ibmax;
|
|
|
|
|
bmax=b[0];
|
|
|
|
|
for (i=0; i < m; i++)
|
|
|
|
|
{
|
|
|
|
|
if (b[i] > bmax) bmax=b[i];
|
|
|
|
|
ibmax = i;
|
|
|
|
|
}
|
|
|
|
|
//cout<<bmax<<endl;
|
|
|
|
|
if (bmax > MAX_ASTERISK)
|
|
|
|
|
return bins;
|
|
|
|
|
}
|
|
|
|
|
void show_histogram_text(vector <size_t> &bins)
|
|
|
|
|
{
|
|
|
|
|
for (size_t i=0; i<bins.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
for(int j=0; j < m; j++)
|
|
|
|
|
if (bins[i]!=0)
|
|
|
|
|
{
|
|
|
|
|
if (b[j]<100)
|
|
|
|
|
{
|
|
|
|
|
cout<<" ";
|
|
|
|
|
}
|
|
|
|
|
if (b[j]<10)
|
|
|
|
|
cout<<bins[i]<<" | " ;
|
|
|
|
|
for (size_t j=0; j<bins[i]; j++)
|
|
|
|
|
{
|
|
|
|
|
cout<<" ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
height = 76 * ( static_cast<double>(b[j]) / bmax);
|
|
|
|
|
hem = 76 * ( static_cast<double>(b[j-1]) / bmax);
|
|
|
|
|
hep = 76 * ( static_cast<double>(b[j+1]) / bmax);
|
|
|
|
|
cout<<b[j]<<'|';
|
|
|
|
|
|
|
|
|
|
if (j==0)
|
|
|
|
|
{
|
|
|
|
|
for (int u=0; u < height; u++)
|
|
|
|
|
{
|
|
|
|
|
if ((b[0] > b[1])&&(u == hep - 1)) cout<<'v';
|
|
|
|
|
else cout<<'*';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (j == m)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
for (int u = 0; u < height; u++)
|
|
|
|
|
{
|
|
|
|
|
if ((b[m] > b[m-1])&&(u == hem-1)) cout<<'^';
|
|
|
|
|
else cout<<'*';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int u=0; u < height; u++)
|
|
|
|
|
{
|
|
|
|
|
sim='*';
|
|
|
|
|
if ((b[j] > b[j-1]) && (u == hem)) sim='^';
|
|
|
|
|
if ((b[j] > b[j+1])&&(u == hep)&&(u != height)&&(u != 0)) sim='V';
|
|
|
|
|
if ((b[j-1] == b[j+1])&&(u == hep)) sim='N';
|
|
|
|
|
cout<<sim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
cout<<"*";
|
|
|
|
|
}
|
|
|
|
|
cout<<endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for(int j=0; j < m; j++)
|
|
|
|
|
{
|
|
|
|
|
if (b[j]<100)
|
|
|
|
|
{
|
|
|
|
|
cout<<" ";
|
|
|
|
|
}
|
|
|
|
|
if (b[j]<10)
|
|
|
|
|
{
|
|
|
|
|
cout<<" ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
height = 76 * ( static_cast<double>(b[j]) / bmax);
|
|
|
|
|
hem = 76 * ( static_cast<double>(b[j-1]) / bmax);
|
|
|
|
|
hep = 76 * ( static_cast<double>(b[j+1]) / bmax);
|
|
|
|
|
cout<<b[j]<<'|';
|
|
|
|
|
|
|
|
|
|
if (j==0)
|
|
|
|
|
{
|
|
|
|
|
for (int u=0; u < b[i]; u++)
|
|
|
|
|
{
|
|
|
|
|
if ((b[0] > b[1])&&(u == b[i+1] - 1)) cout<<'v';
|
|
|
|
|
else cout<<'*';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (j == m)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
auto in = input_data();
|
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
show_histogram_text(bins);
|
|
|
|
|
|
|
|
|
|
for (int u = 0; u < b[i]; u++)
|
|
|
|
|
{
|
|
|
|
|
if ((b[m] > b[m-1])&&(u == b[i-1]-1)) cout<<'^';
|
|
|
|
|
else cout<<'*';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int u=0; u < b[i]; u++)
|
|
|
|
|
{
|
|
|
|
|
sim='*';
|
|
|
|
|
if ((b[j] > b[j-1]) && (u == b[i-1])) sim='^';
|
|
|
|
|
if ((b[j] > b[j+1])&&(u == b[i+1])&&(u != b[i])&&(u != 0)) sim='V';
|
|
|
|
|
if ((b[j-1] == b[j+1])&&(u == b[i+1])) sim='N';
|
|
|
|
|
cout<<sim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cout<<endl;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|