#include <iostream>
#include <vector>
#include <string>
#include "histogram.hpp"
#include "text.hpp"

using namespace std;

struct Input {
    vector<double> numbers;
    size_t bin_count{};
};

Input input_data() {
    size_t number_count;
    
    cerr << "Введите кол-во чисел в строке: ";
    cin >> number_count;
    Input in;
    in.numbers.resize(number_count);
    
    cerr << "Введите строку чисел: ";
    for (int i = 0; i < number_count; i++) {
        cin >> in.numbers[i];
    }
    
    cerr << "Введите кол-во корзин: ";
    cin >> in.bin_count;
    return in;
}

//void find_minmax(const vector<double>& numbers, double& minimum, double& maximum) {
//    minimum = numbers[0];
//    for (int i : numbers) {
//        if (i < minimum) minimum = i;
//    }
//    maximum = numbers[0];
//    for (int i : numbers) {
//        if (i > maximum) maximum = i;
//    }
//}

//vector<size_t> make_histogram(const vector<double>& numbers, size_t& bin_count) {
//    vector <size_t> baskets;
//    baskets.resize(bin_count);
//    
//    double basket_max;
//    double basket_min;
//    double basket_size;
//    
//    find_minmax(numbers, basket_min, basket_max);
//    basket_size = (basket_max - basket_min) / bin_count;
//    for (int i = 0; i < bin_count; i++) {
//        for (int j = 0; j < numbers.size(); j++) {
//            if ((numbers[j] >= (basket_min + i * basket_size) and numbers[j] < (basket_min + (i + 1) * basket_size)) or (i == bin_count - 1 and numbers[j] == basket_max)) {
//                baskets[i]++;
//            }
//        }
//    }
//    return baskets;
//}

//void show_histogram_text(const vector<size_t>& baskets) {
//    const size_t screen_width = 80;
//    const size_t max_asterisk = screen_width - 3 - 1;
//    cout.precision(4);
//    size_t baskets_max_count;
//    
//    baskets_max_count = baskets[0];
//    for (size_t i : baskets) {
//        if (i > baskets_max_count) baskets_max_count = i;
//    }
//    for (int i = 0; i < baskets.size(); i++) {
//        size_t height = baskets[i];
//        if (baskets_max_count > max_asterisk) {
//            height = max_asterisk * (static_cast<double>(baskets[i]) / baskets_max_count);
//        }
//        cout << baskets[i] << "|";
//        for (int j = 0; j < height; j++) cout << "*";
//        cout << endl;
//    }
//}

int main () {
    auto in = input_data();
    auto bins = make_histogram(in.numbers, in.bin_count);
    show_histogram_text(bins);
    return 0;
}