|
|
@ -3,7 +3,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Input {
|
|
|
|
struct Input {
|
|
|
|
vector<double> numbers;
|
|
|
|
vector<double> numbers;
|
|
|
|
size_t bin_count{};
|
|
|
|
size_t bin_count{};
|
|
|
@ -13,32 +12,26 @@ struct Input {
|
|
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
Input
|
|
|
|
input_data() {
|
|
|
|
input_data() {
|
|
|
|
|
|
|
|
size_t number_count;
|
|
|
|
|
|
|
|
cerr<<"Enter number count";
|
|
|
|
|
|
|
|
cin >> number_count;
|
|
|
|
Input in;
|
|
|
|
Input in;
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
cin >> in.number_count;
|
|
|
|
vector<double> numbers(number_count);
|
|
|
|
|
|
|
|
cerr<<"Enter numbers";
|
|
|
|
|
|
|
|
for (size_t i = 0; i < number_count; i++) {
|
|
|
|
vector<double> numbers(in.number_count);
|
|
|
|
|
|
|
|
in.numbers.resize(in.number_count);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < in.number_count; i++) {
|
|
|
|
|
|
|
|
cin >> in.numbers[i];
|
|
|
|
cin >> in.numbers[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t bin_count;
|
|
|
|
size_t bin_count;
|
|
|
|
cerr<<"Enter bin count";
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
cin >> in.bin_count;
|
|
|
|
cin >> in.bin_count;
|
|
|
|
return in;
|
|
|
|
|
|
|
|
|
|
|
|
size_t max_count;
|
|
|
|
|
|
|
|
in.max_count = 0;
|
|
|
|
|
|
|
|
return in;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|
|
|
find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|
|
|
min = numbers[0];
|
|
|
|
min = numbers[0];
|
|
|
|
max = numbers[0];
|
|
|
|
max = numbers[0];
|
|
|
|
for (double x : numbers)
|
|
|
|
for (double x : numbers){
|
|
|
|
{
|
|
|
|
|
|
|
|
if (x < min){
|
|
|
|
if (x < min){
|
|
|
|
min = x;
|
|
|
|
min = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -48,31 +41,25 @@ find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vector <size_t>
|
|
|
|
vector<size_t> make_histogram(const vector<double> numbers, size_t bin_count){
|
|
|
|
make_histogram(const vector<double>& numbers, size_t & bin_count, size_t & number_count, size_t & max_count) {
|
|
|
|
vector<size_t> bins(bin_count);
|
|
|
|
double min, max;
|
|
|
|
double max, min = 0;
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
double bin_size = (max - min) / bin_count;
|
|
|
|
double bin_size = (max - min) / bin_count;
|
|
|
|
vector<size_t> bins(bin_count);
|
|
|
|
|
|
|
|
max_count = bins[0];
|
|
|
|
for (size_t i = 0; i < numbers.size(); i++) {
|
|
|
|
for (size_t i = 0; i < number_count; i++){
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
bool found = false;
|
|
|
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++){
|
|
|
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++) {
|
|
|
|
auto lo = min + j * bin_size;
|
|
|
|
auto lo = min + j * bin_size;
|
|
|
|
auto hi = min + (j + 1) * bin_size;
|
|
|
|
auto hi = min + (j + 1) * bin_size;
|
|
|
|
if ((lo <= numbers[i]) && (numbers[i] < hi)){
|
|
|
|
if ((lo <= numbers[i]) && (numbers[i] < hi)) {
|
|
|
|
bins[j]++;
|
|
|
|
bins[j]++;
|
|
|
|
found = true;
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bins[j] > max_count){
|
|
|
|
|
|
|
|
max_count = bins[j];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found){
|
|
|
|
if (!found) {
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bins[bin_count - 1] > max_count){
|
|
|
|
|
|
|
|
max_count = bins[bin_count - 1];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bins;
|
|
|
|
return bins;
|
|
|
@ -109,9 +96,10 @@ if (max_count > MAX_ASTERISK){
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto in = input_data();
|
|
|
|
auto in = input_data();
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count, in.number_count, in.max_count);
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
show_histogram_text(bins, in.max_count, in.bin_count);
|
|
|
|
show_histogram_text(bins, in.max_count, in.bin_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|