Andrey 2 лет назад
Родитель ade892e744
Сommit 19165482b1

@ -33,6 +33,9 @@
<Add option="-fexceptions" />
</Compiler>
<Unit filename=".gitignore" />
<Unit filename="histogram.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="main.cpp" />
<Extensions>
<lib_finder disable_auto="1" />

@ -4,78 +4,79 @@
using namespace std;
struct Input {
struct
Input
{
vector<double> numbers;
size_t bin_count{};
};
};
Input
input_data(){
Input
input_data()
{
size_t number_count;
cin >> number_count;
Input in;
in.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++) {
cin >> in.numbers[i];
for (size_t i = 0; i < number_count; i++)
{
cin >> in.numbers[i];
}
size_t bin_count;
cin >> in.bin_count;
return in;
}
}
void find_minmax(const vector<double> numbers, double& min, double& max)
{
void
find_minmax(const vector<double>& numbers, double& min, double& max)
{
max = numbers[0];
min = numbers[0];
for(size_t i = 0; i < numbers.size(); i++)
{
{
if (numbers[i] > max) max = numbers[i];
if (numbers[i] < min) min = numbers[i];
}
}
}
vector<double> make_histogram(const vector<double> numbers, size_t bin_count)
{
void
make_histogram(vector<double>& bins, Input in)
{
double min, max;
find_minmax(numbers, min, max);
vector<double> bins;
find_minmax(in.numbers, min, max);
size_t cor_size = (max - min)/in.bin_count;
size_t cor_size = (max - min)/bin_count;
for (size_t i = 0; i < numbers.size(); i++)
for (size_t i = 0; i < in.numbers.size(); i++)
{
bool flag = false;
for (size_t j = 0; (j < bin_count - 1) && !flag; j++)
for (size_t j = 0; (j < in.bin_count) && !flag; j++)
{
auto L = min + j*cor_size;
auto H = min + (j+1)*cor_size;
if ((L <= numbers[i]) && (numbers[i] < H))
{
flag = true;
bins[j]++;
}
auto L = min + j*cor_size;
auto H = min + (j+1)*cor_size;
if ((L <= in.numbers[i]) && (in.numbers[i] <= H))
{
flag = true;
bins[j]++;
}
}
if (!flag) bins[bin_count-1]++;
}
return bins;
if (!flag) bins[in.bin_count-1]++;
}
}
void show_histogram_text(vector<double> bins, const vector<double> numbers, size_t bin_count)
{
void
show_histogram_text(vector<double> bins, Input in)
{
const size_t MAX_ASTERISK = 76;
int maxb = bins[0];
size_t H;
for (size_t j = 1; j < bin_count; j++)
for (size_t j = 1; j < in.bin_count; j++)
{
if (bins[j] > maxb) maxb = bins[j];
}
for (size_t j = 0; j < bin_count; j++)
for (size_t j = 0; j < in.bin_count; j++)
{
if (maxb > MAX_ASTERISK)
{
@ -88,27 +89,14 @@ using namespace std;
for (size_t i = 0; i < H; i++) cout << "*";
cout << endl;
}
}
}
/////////////////////////////////////////////////////////
int main()
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 cout << "empirii";
cout << endl;
}
/////////////////////////////////////////////////////////
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins, in.numbers, in.bin_count);
return 0;
vector<double> bins;
bins.resize(in.bin_count);
make_histogram(bins, in);
show_histogram_text(bins, in);
}

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