|
|
|
@ -12,6 +12,7 @@ struct Input {
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
input_data(){
|
|
|
|
|
|
|
|
|
|
size_t number_count;
|
|
|
|
|
cerr << "Enter number_count: ";
|
|
|
|
|
cin >> number_count;
|
|
|
|
@ -19,7 +20,7 @@ input_data(){
|
|
|
|
|
Input in;
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
|
cerr << "Enter numbers: ";
|
|
|
|
|
for (size_t i = 0; i < number_count; i++) {
|
|
|
|
|
for (size_t i = 0; i < number_count; i++){
|
|
|
|
|
cin >> in.numbers[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -27,14 +28,13 @@ input_data(){
|
|
|
|
|
cin >> in.bin_count;
|
|
|
|
|
|
|
|
|
|
return in;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|
|
|
|
find_minmax(vector<double>& numbers, double& min, double& max){
|
|
|
|
|
min = numbers[0];
|
|
|
|
|
max = numbers[0];
|
|
|
|
|
for (double x : numbers) {
|
|
|
|
|
for (double x : numbers) {
|
|
|
|
|
if (x < min) {
|
|
|
|
|
min = x;
|
|
|
|
|
}
|
|
|
|
@ -44,49 +44,65 @@ find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main()
|
|
|
|
|
{
|
|
|
|
|
Input in = input_data();
|
|
|
|
|
|
|
|
|
|
//size_t i, bin;
|
|
|
|
|
vector<size_t> make_histogram(vector<double>& numbers, size_t bin_count) {
|
|
|
|
|
double min, max;
|
|
|
|
|
find_minmax(in.numbers, min, max);
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
|
|
|
|
|
// vector<size_t> bins(bin_count);
|
|
|
|
|
//double bin_size = (max - min) / bin_count;
|
|
|
|
|
vector<size_t> bins(bin_count, 0);
|
|
|
|
|
double bin_size = (max - min) / bin_count;
|
|
|
|
|
|
|
|
|
|
/*for (size_t i = 0; i < number_count; i++) {
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++) {
|
|
|
|
|
auto lo = min + j * bin_size;
|
|
|
|
|
auto hi = min + (j + 1) * bin_size;
|
|
|
|
|
if ((lo <= numbers[i]) && (numbers[i] < hi)) {
|
|
|
|
|
bins[j]++;
|
|
|
|
|
found = true;
|
|
|
|
|
}
|
|
|
|
|
for (double number : numbers) {
|
|
|
|
|
size_t bin_index = bin_count - 1; // default to last bin
|
|
|
|
|
if (number < max) {
|
|
|
|
|
bin_index = static_cast<size_t>((number - min) / bin_size);
|
|
|
|
|
}
|
|
|
|
|
if (!found) {
|
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
|
}
|
|
|
|
|
bins[bin_index]++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bins;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void show_histogram_text(const vector<size_t>& bins){
|
|
|
|
|
size_t i;
|
|
|
|
|
size_t height = 0;
|
|
|
|
|
size_t max_count = 0;
|
|
|
|
|
for (i = 0; i < bin_count; i++){
|
|
|
|
|
if (bins[i] > max_count) max_count = bins[i];
|
|
|
|
|
for (size_t x: bins) {
|
|
|
|
|
if (x > max_count) {
|
|
|
|
|
max_count = x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(size_t bin:bins){
|
|
|
|
|
size_t height = bin;
|
|
|
|
|
height = MAX_ASTERISK * (static_cast<double>(bin) / max_count);
|
|
|
|
|
for(size_t i = 0; i < height; i++){
|
|
|
|
|
cout<<"*";
|
|
|
|
|
if (max_count > MAX_ASTERISK) {
|
|
|
|
|
for(size_t bin:bins){
|
|
|
|
|
size_t height = bin;
|
|
|
|
|
height = MAX_ASTERISK * (static_cast<double>(bin) / max_count);
|
|
|
|
|
for(size_t i = 0; i < height; i++){
|
|
|
|
|
cout<<"*";
|
|
|
|
|
}
|
|
|
|
|
cout<<"|";
|
|
|
|
|
if(bin<100) cout<<" ";
|
|
|
|
|
if(bin<10) cout<<" ";
|
|
|
|
|
cout<<bin<<endl;
|
|
|
|
|
}
|
|
|
|
|
cout<<"|";
|
|
|
|
|
if(bin<100) cout<<" ";
|
|
|
|
|
if(bin<10) cout<<" ";
|
|
|
|
|
cout<<bin<<endl;
|
|
|
|
|
}*/
|
|
|
|
|
} else {
|
|
|
|
|
for(size_t bin:bins){
|
|
|
|
|
size_t height = bin;
|
|
|
|
|
for(size_t i = 0; i < height; i++){
|
|
|
|
|
cout<<"*";
|
|
|
|
|
}
|
|
|
|
|
cout<<"|";
|
|
|
|
|
if(bin<100) cout<<" ";
|
|
|
|
|
if(bin<10) cout<<" ";
|
|
|
|
|
cout<<bin<<endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main()
|
|
|
|
|
{
|
|
|
|
|
auto in = input_data();
|
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
show_histogram_text(bins);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|