MachulinaDV 2 лет назад
Родитель 173e6c3cff
Сommit b48771966c

@ -5,46 +5,63 @@
using namespace std; using namespace std;
int main() struct Input {
{ vector<double>A;
size_t n, bin, height; size_t bin{};
string str = "*"; };
double max, min, step, a;
int i, j;
Input
input_data()
{
size_t n;
cerr<<"Marks: "; cerr<<"Marks: ";
cin>>n; cin>>n;
vector<double>A(n); Input in;
in.A.resize(n);
for (size_t i=0; i<n; i++)
for (i=0; i<n; i++)
{ {
cerr<<"A["<<i<<"]="; cerr<<"A["<<i<<"]=";
cin>>A[i]; cin>>in.A[i];
} }
cerr<<"Rows: "; cerr<<"Rows: ";
cin>>bin; cin>>in.bin;
return in;
vector<size_t>B(bin); }
max = 0; void find_minmax(const vector<double>& A, double& min, double& max)
min = 10; {
min = A[0];
for (auto i = 0; i<A.size(); i++)
{
if (A[i]<min)
{
min = A[i];
}
}
for (i=0; i<n; i++) max = A[0];
for (auto i = 0; i<A.size(); i++)
{ {
if (A[i]>max) if (A[i]>max)
{
max = A[i]; max = A[i];
if (A[i]<min)
min = A[i];
} }
}
}
step = (max-min)/bin; vector <size_t> make_histogram (const vector<double>& A, size_t bin)
{
vector<size_t>B(bin);
size_t max_count;
double max, min;
find_minmax(A, min, max);
double step = (max-min)/(bin);
for (i=0; i<n; i++) for (size_t i=0; i<A.size(); i++)
{ {
for (j=0; j<bin; j++) for (size_t j=0; j<bin; j++)
{ {
if ((A[i]>=(min+j*step))&&(A[i]<(min+(j+1)*step))) if ((A[i]>=(min+j*step))&&(A[i]<(min+(j+1)*step)))
{ {
@ -54,13 +71,17 @@ int main()
} }
} }
for (i=0; i<n; i++) for (size_t i=0; i<A.size(); i++)
{ {
if (A[i]== max) if (A[i]== max)
B[bin-1]++; B[bin-1]++;
} }
return B;
}
for (i=0; i<bin; i++) void show_histogram(vector<size_t>B, size_t bin)
{
for (size_t i=0; i<bin; i++)
{ {
if (B[i]<10) if (B[i]<10)
{ {
@ -71,14 +92,23 @@ int main()
cout<<" "; cout<<" ";
} }
cout<<B[i]<<"|"; cout<<B[i]<<"|";
for (j=0; j<B[i]; j++) for (size_t j=0; j<B[i]; j++)
{ {
cout<<"*"; cout<<"*";
} }
cout<<endl; cout<<endl;
} }
}
int main()
{
Input in = input_data();
auto B = make_histogram(in.A, in.bin);
show_histogram (B, in.bin);
return 0; return 0;
} }

Загрузка…
Отмена
Сохранить