Сommit
						8c0597f45f
					
				@ -0,0 +1,70 @@
 | 
				
			|||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct Input
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    vector<double> numbers;
 | 
				
			||||||
 | 
					    size_t bin_count{};
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Input input_data()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    size_t number_count;
 | 
				
			||||||
 | 
					    cerr << "Number count: ";
 | 
				
			||||||
 | 
					    cin >> number_count;
 | 
				
			||||||
 | 
					    Input in;
 | 
				
			||||||
 | 
					    in.numbers.resize(number_count);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    cerr << "Numbers: ";
 | 
				
			||||||
 | 
					    for (size_t i = 0; i < number_count; i++) {
 | 
				
			||||||
 | 
					        cin >> in.numbers[i];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    cerr << "Enter bin count:";
 | 
				
			||||||
 | 
					    cin >> in.bin_count;
 | 
				
			||||||
 | 
					    return in;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void find_minmax(const vector<double>& numbers, double& min, double& max) {
 | 
				
			||||||
 | 
					    if (numbers.empty()) {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    min = numbers[0];
 | 
				
			||||||
 | 
					    max = numbers[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (double x : numbers) {
 | 
				
			||||||
 | 
					        if (x < min) min = x;
 | 
				
			||||||
 | 
					        if (x > max) max = x;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main() {
 | 
				
			||||||
 | 
					    auto in = input_data();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    double min, max;
 | 
				
			||||||
 | 
					    find_minmax(in.numbers, min, max);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    vector<size_t> bins(in.bin_count);
 | 
				
			||||||
 | 
					    for (double x : in.numbers) {
 | 
				
			||||||
 | 
					        size_t bin_index = (x - min) / (max - min) * in.bin_count;
 | 
				
			||||||
 | 
					        if (bin_index == in.bin_count) bin_index--;
 | 
				
			||||||
 | 
					        bins[bin_index]++;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const size_t SCREEN_WIDTH = 80;
 | 
				
			||||||
 | 
					    size_t max_count = 0;
 | 
				
			||||||
 | 
					    for (size_t count : bins) {
 | 
				
			||||||
 | 
					        if (count > max_count) max_count = count;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (size_t bin : bins) {
 | 
				
			||||||
 | 
					        size_t height = bin * SCREEN_WIDTH / max_count;
 | 
				
			||||||
 | 
					        for (size_t i = 0; i < height; i++) {
 | 
				
			||||||
 | 
					            cout << '*';
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        cout << endl;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
					Загрузка…
					
					
				
		Ссылка в новой задаче