|
|
|
@ -4,86 +4,111 @@
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
const size_t MAX_ASTERISK = 76;
|
|
|
|
|
size_t cor, col, H;
|
|
|
|
|
int i, j;
|
|
|
|
|
double max1, min1;
|
|
|
|
|
struct Input {
|
|
|
|
|
vector<double> numbers;
|
|
|
|
|
size_t bin_count{};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
cerr << "vvedite col-vo col:";
|
|
|
|
|
cin >> col;
|
|
|
|
|
Input
|
|
|
|
|
input_data(){
|
|
|
|
|
|
|
|
|
|
vector <double> A(col);
|
|
|
|
|
vector <double> B(col);
|
|
|
|
|
size_t number_count;
|
|
|
|
|
cin >> number_count;
|
|
|
|
|
Input in;
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < col; i++)
|
|
|
|
|
{
|
|
|
|
|
cerr << "A[" << i << "]=";
|
|
|
|
|
cin >> A[i];
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
|
for (size_t i = 0; i < number_count; i++) {
|
|
|
|
|
cin >> in.numbers[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cerr << "vvedite col-vo cor:";
|
|
|
|
|
cin >> cor;
|
|
|
|
|
size_t bin_count;
|
|
|
|
|
cin >> in.bin_count;
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cor == 0)
|
|
|
|
|
void find_minmax(const vector<double> numbers, double& min, double& max)
|
|
|
|
|
{
|
|
|
|
|
cor = sqrt(col);
|
|
|
|
|
if (cor > 25)
|
|
|
|
|
max = numbers[0];
|
|
|
|
|
min = numbers[0];
|
|
|
|
|
for(size_t i = 0; i < numbers.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
cor = 1 + log2(col);
|
|
|
|
|
cout << "sterg";
|
|
|
|
|
if (numbers[i] > max) max = numbers[i];
|
|
|
|
|
if (numbers[i] < min) min = numbers[i];
|
|
|
|
|
}
|
|
|
|
|
else cout << "empirii";
|
|
|
|
|
cout << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
max1 = A[0]; min1 = A[0];
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < col; i++)
|
|
|
|
|
vector<double> make_histogram(const vector<double> numbers, size_t bin_count)
|
|
|
|
|
{
|
|
|
|
|
if (A[i] > max1) max1 = A[i];
|
|
|
|
|
if (A[i] < min1) min1 = A[i];
|
|
|
|
|
}
|
|
|
|
|
double min, max;
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
vector<double> bins;
|
|
|
|
|
|
|
|
|
|
double cor_size = (max1 - min1)/cor;
|
|
|
|
|
size_t cor_size = (max - min)/bin_count;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < col; i++)
|
|
|
|
|
for (size_t i = 0; i < numbers.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
bool flag = false;
|
|
|
|
|
for (j = 0; (j < cor - 1) && !flag; j++)
|
|
|
|
|
for (size_t j = 0; (j < bin_count - 1) && !flag; j++)
|
|
|
|
|
{
|
|
|
|
|
auto L = min1 + j*cor_size;
|
|
|
|
|
auto H = min1 + (j+1)*cor_size;
|
|
|
|
|
if ((L <= A[i]) && (A[i] < H))
|
|
|
|
|
auto L = min + j*cor_size;
|
|
|
|
|
auto H = min + (j+1)*cor_size;
|
|
|
|
|
if ((L <= numbers[i]) && (numbers[i] < H))
|
|
|
|
|
{
|
|
|
|
|
flag = true;
|
|
|
|
|
B[j]++;
|
|
|
|
|
bins[j]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!flag) B[cor-1]++;
|
|
|
|
|
if (!flag) bins[bin_count-1]++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int maxb = B[0];
|
|
|
|
|
return bins;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (j = 1; j < cor; j++)
|
|
|
|
|
void show_histogram_text(vector<double> bins, const vector<double> numbers, size_t bin_count)
|
|
|
|
|
{
|
|
|
|
|
if (B[j] > maxb) maxb = B[j];
|
|
|
|
|
const size_t MAX_ASTERISK = 76;
|
|
|
|
|
int maxb = bins[0];
|
|
|
|
|
size_t H;
|
|
|
|
|
|
|
|
|
|
for (size_t j = 1; j < bin_count; j++)
|
|
|
|
|
{
|
|
|
|
|
if (bins[j] > maxb) maxb = bins[j];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (j = 0; j < cor; j++)
|
|
|
|
|
for (size_t j = 0; j < bin_count; j++)
|
|
|
|
|
{
|
|
|
|
|
if (maxb > MAX_ASTERISK)
|
|
|
|
|
{
|
|
|
|
|
H = MAX_ASTERISK * (static_cast<double>(B[j]) / maxb);
|
|
|
|
|
H = MAX_ASTERISK * (static_cast<double>(bins[j]) / maxb);
|
|
|
|
|
}
|
|
|
|
|
else H = bins[j];
|
|
|
|
|
if (bins[j] < 100) cout << " ";
|
|
|
|
|
if (bins[j] < 10) cout << " ";
|
|
|
|
|
cout << bins[j] << "|";
|
|
|
|
|
for (size_t i = 0; i < H; i++) cout << "*";
|
|
|
|
|
cout << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
auto in = input_data();
|
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
|
if (in.bin_count == 0)
|
|
|
|
|
{
|
|
|
|
|
in.bin_count = sqrt(in.numbers.size());
|
|
|
|
|
if (in.bin_count > 25)
|
|
|
|
|
{
|
|
|
|
|
in.bin_count = 1 + log2(in.numbers.size());
|
|
|
|
|
cout << "sterg";
|
|
|
|
|
}
|
|
|
|
|
else H = B[j];
|
|
|
|
|
if (B[j] < 100) cout << " ";
|
|
|
|
|
if (B[j] < 10) cout << " ";
|
|
|
|
|
cout << B[j] << "|";
|
|
|
|
|
for (i = 0; i < H; i++) cout << "*";
|
|
|
|
|
else cout << "empirii";
|
|
|
|
|
cout << endl;
|
|
|
|
|
}
|
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
show_histogram_text(bins, in.numbers, in.bin_count);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|