| 
						
						
						
					 | 
					 | 
					@ -1,24 +1,37 @@
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#include <iostream>
 | 
					 | 
					 | 
					 | 
					#include <iostream>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#include <vector>
 | 
					 | 
					 | 
					 | 
					#include <vector>
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#include <cmath>
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					using namespace std;
 | 
					 | 
					 | 
					 | 
					using namespace std;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					const size_t SCREEN_WIDTH = 80;
 | 
					 | 
					 | 
					 | 
					struct Input {
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					const size_t MAX_ASTERISK = SCREEN_WIDTH - 4;
 | 
					 | 
					 | 
					 | 
					    vector<double> numbers;
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    size_t bin_count{};
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					Input input_data() {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					int main() {
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    size_t number_count;
 | 
					 | 
					 | 
					 | 
					    size_t number_count;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    cerr << "Enter number count: ";
 | 
					 | 
					 | 
					 | 
					    cerr << "Enter number count: ";
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    cin >> number_count;
 | 
					 | 
					 | 
					 | 
					    cin >> number_count;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    vector<double> numbers(number_count);
 | 
					 | 
					 | 
					 | 
					    Input in;
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    cout << "Enter bin count: ";
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    cin >> in.bin_count;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    in.numbers.resize(number_count);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    in.bin_count.resize(bin_count);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    cerr << "Enter numbers: ";
 | 
					 | 
					 | 
					 | 
					    cerr << "Enter numbers: ";
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    for (size_t i = 0; i < number_count; i++) {
 | 
					 | 
					 | 
					 | 
					    for (size_t i = 0; i < number_count; i++) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        cin >> numbers[i];
 | 
					 | 
					 | 
					 | 
					        cin >> in.numbers[i];
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    return in;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    double min = numbers[0];
 | 
					 | 
					 | 
					 | 
					void find_minmax(const vector<double> &numbers, double &min, double &max){
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    double max = numbers[0];
 | 
					 | 
					 | 
					 | 
					    min = numbers[0];
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    max = numbers[0];
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    for (double x : numbers) {
 | 
					 | 
					 | 
					 | 
					    for (double x : numbers) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (x < min) {
 | 
					 | 
					 | 
					 | 
					        if (x < min) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            min = x;
 | 
					 | 
					 | 
					 | 
					            min = x;
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -27,48 +40,43 @@ int main() {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            max = x;
 | 
					 | 
					 | 
					 | 
					            max = x;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }
 | 
					 | 
					 | 
					 | 
					        }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    size_t bin_count;
 | 
					 | 
					 | 
					 | 
					int main(){
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    cerr << "Enter bin count: ";
 | 
					 | 
					 | 
					 | 
					    Input in = input_data();
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    cin >> bin_count;
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    if (bin_count == 0) {
 | 
					 | 
					 | 
					 | 
					    vector<size_t> bins ( in.bin_count );
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        bin_count = int(sqrt(number_count));
 | 
					 | 
					 | 
					 | 
					    double min = in.numbers[0];
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (bin_count > 25) {
 | 
					 | 
					 | 
					 | 
					    double max = in.numbers[0];
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            bin_count = int(1 + log2(number_count));
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            cerr << "Calculated " << bin_count << " bins with Sturges' formula" << endl;
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        else {
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            cerr << "Calculated " << bin_count << " bins with Empiric formula" << endl;
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    vector<size_t> bins(bin_count, 0);
 | 
					 | 
					 | 
					 | 
					    find_minmax(in.numbers, min, max);
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    double bin_size = (max - min) / bin_count;
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    for (size_t i = 0; i < number_count; i++) {
 | 
					 | 
					 | 
					 | 
					    double bin_size = (max - min) / in.bin_count;
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    for (size_t i = 0; i < in.number.size(); i++) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        bool found = false;
 | 
					 | 
					 | 
					 | 
					        bool found = false;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        for (size_t j = 0; (j < (bin_count - 1)) && !found; j++) {
 | 
					 | 
					 | 
					 | 
					        for (size_t j = 0; (j < (in.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 <= in.numbers[i]) && (in.numbers[i] < hi)) {
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                bins[j]++;
 | 
					 | 
					 | 
					 | 
					                bins[j]++;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                found = true;
 | 
					 | 
					 | 
					 | 
					                found = true;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            }
 | 
					 | 
					 | 
					 | 
					            }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }
 | 
					 | 
					 | 
					 | 
					        }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (!found) {
 | 
					 | 
					 | 
					 | 
					        if (!found) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            bins[bin_count - 1]++;
 | 
					 | 
					 | 
					 | 
					            bins[in.bin_count - 1]++;
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }
 | 
					 | 
					 | 
					 | 
					        }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    size_t maxbin = bins[0];
 | 
					 | 
					 | 
					 | 
					    size_t maxbin = bins[0];
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    for (size_t i=1; i < bins.size(); i++){
 | 
					 | 
					 | 
					 | 
					    for (size_t i=1; i < in.bin_count; i++){
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if (maxbin < bins[i]){
 | 
					 | 
					 | 
					 | 
					        if (maxbin < bins[i]){
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            maxbin = bins[i];
 | 
					 | 
					 | 
					 | 
					            maxbin = bins[i];
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }
 | 
					 | 
					 | 
					 | 
					        }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    }
 | 
					 | 
					 | 
					 | 
					    }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    if (maxbin <= MAX_ASTERISK){
 | 
					 | 
					 | 
					 | 
					    if (maxbin <= MAX_ASTERISK){
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        for (size_t i = 0; i < bins.size(); i++) {
 | 
					 | 
					 | 
					 | 
					        for (size_t i = 0; i < in.bin_count; i++) {
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            cout.width(4);
 | 
					 | 
					 | 
					 | 
					            cout.width(4);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            cout << bins[i] << "|";
 | 
					 | 
					 | 
					 | 
					            cout << bins[i] << "|";
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            for (size_t j = 0; j < bins[i]; j++) {
 | 
					 | 
					 | 
					 | 
					            for (size_t j = 0; j < bins[i]; j++) {
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -78,7 +86,7 @@ int main() {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        }
 | 
					 | 
					 | 
					 | 
					        }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return 0;
 | 
					 | 
					 | 
					 | 
					        return 0;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    } else {
 | 
					 | 
					 | 
					 | 
					    } else {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        for (size_t i = 0; i < bins.size(); i++) {
 | 
					 | 
					 | 
					 | 
					        for (size_t i = 0; i < in.bin_count; i++) {
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            cout.width(4);
 | 
					 | 
					 | 
					 | 
					            cout.width(4);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            cout << bins[i] << "|";
 | 
					 | 
					 | 
					 | 
					            cout << bins[i] << "|";
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            size_t height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bins[i]) / maxbin));
 | 
					 | 
					 | 
					 | 
					            size_t height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bins[i]) / maxbin));
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
 
 |