|
|
|
@ -2,50 +2,58 @@
|
|
|
|
|
#include <vector>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 6 - 1;
|
|
|
|
|
size_t bin_count, counts;
|
|
|
|
|
cerr << "Enter counts:";
|
|
|
|
|
cin >> counts;
|
|
|
|
|
|
|
|
|
|
vector <double> numbers(counts);
|
|
|
|
|
struct Input {
|
|
|
|
|
vector<double> numbers;
|
|
|
|
|
size_t bin_count{};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < counts; i++){
|
|
|
|
|
cerr << "Enter array "<< i <<" number:";
|
|
|
|
|
cin >> numbers[i];
|
|
|
|
|
Input
|
|
|
|
|
input_data(){
|
|
|
|
|
size_t number_count;
|
|
|
|
|
cin >> number_count;
|
|
|
|
|
|
|
|
|
|
Input in;
|
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < number_count; i++){
|
|
|
|
|
cin >> in.numbers[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cerr << "Enter bin_count:";
|
|
|
|
|
cin >> bin_count;
|
|
|
|
|
cin >> in.bin_count;
|
|
|
|
|
|
|
|
|
|
double minN = numbers[0], maxN = numbers[0];
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
find_minmax(const vector<double>& numbers, double& min, double& max){
|
|
|
|
|
min = numbers[0];
|
|
|
|
|
max = numbers[0];
|
|
|
|
|
for (double x: numbers){
|
|
|
|
|
if (minN > x){
|
|
|
|
|
minN = x;
|
|
|
|
|
if (min > x){
|
|
|
|
|
min = x;
|
|
|
|
|
}
|
|
|
|
|
if (max < x){
|
|
|
|
|
max = x;
|
|
|
|
|
}
|
|
|
|
|
if (maxN < x){
|
|
|
|
|
maxN = x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double diff = (maxN - minN) / bin_count;
|
|
|
|
|
|
|
|
|
|
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count){
|
|
|
|
|
double min, max;
|
|
|
|
|
vector <size_t> bins(bin_count);
|
|
|
|
|
|
|
|
|
|
find_minmax(numbers, min, max);
|
|
|
|
|
double diff = (max - min) / bin_count;
|
|
|
|
|
size_t max_count = 0;
|
|
|
|
|
for (size_t i = 0; i < counts; i++){
|
|
|
|
|
for (double x: numbers){
|
|
|
|
|
bool found = false;
|
|
|
|
|
for (size_t j = 0;(j < bin_count - 1) && !found; j++){
|
|
|
|
|
auto lo = minN + j * diff;
|
|
|
|
|
auto hi = minN + (j + 1) * diff;
|
|
|
|
|
if ((lo <= numbers[i]) && (hi > numbers[i])){
|
|
|
|
|
auto lo = min + j * diff;
|
|
|
|
|
auto hi = min + (j + 1) * diff;
|
|
|
|
|
if ((lo <= x) && (hi > x)){
|
|
|
|
|
bins[j]++;
|
|
|
|
|
if (bins[j] > max_count){
|
|
|
|
|
max_count = bins[j];
|
|
|
|
|
}
|
|
|
|
|
found = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -56,41 +64,33 @@ int main()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool scaling = false;
|
|
|
|
|
|
|
|
|
|
if (max_count > MAX_ASTERISK){
|
|
|
|
|
scaling = true;
|
|
|
|
|
return bins;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < bin_count; i++){
|
|
|
|
|
void show_histogram_text(const vector<size_t>& bins){
|
|
|
|
|
for (double x: bins){
|
|
|
|
|
cout << " ";
|
|
|
|
|
if (bins[i] < 100){
|
|
|
|
|
if (x < 100){
|
|
|
|
|
cout << " ";
|
|
|
|
|
}
|
|
|
|
|
if (bins[i] < 10){
|
|
|
|
|
if (x < 10){
|
|
|
|
|
cout << " ";
|
|
|
|
|
}
|
|
|
|
|
cout << bins[i] << "|";
|
|
|
|
|
|
|
|
|
|
size_t number_of_stars = bins[i];
|
|
|
|
|
cout << x << "|";
|
|
|
|
|
|
|
|
|
|
if (scaling){
|
|
|
|
|
if (bins[i] == max_count){
|
|
|
|
|
number_of_stars = MAX_ASTERISK * 1.0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
number_of_stars = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
size_t number_of_stars = x;
|
|
|
|
|
|
|
|
|
|
for (size_t j = 0; j < number_of_stars; j++){
|
|
|
|
|
cout << "*";
|
|
|
|
|
}
|
|
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
|
|
if (i < bin_count - 1){
|
|
|
|
|
cout << minN + (i + 1) * diff << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(){
|
|
|
|
|
auto in = input_data();
|
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
show_histogram_text(bins);
|
|
|
|
|
}
|
|
|
|
|