|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
const size_t SCREEN_WIDTH = 80;
|
|
|
|
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
struct Input {
|
|
|
|
|
vector<double> numbers;
|
|
|
|
@ -19,8 +22,7 @@ input_data() {
|
|
|
|
|
cin >> in.bin_count;
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
void
|
|
|
|
|
find_minmax(const vector<double>& numbers, double& Min, double& Max) {
|
|
|
|
|
void find_minmax(const vector<double>& numbers, double& Min, double& Max) {
|
|
|
|
|
Min = numbers[0];
|
|
|
|
|
Max = numbers[0];
|
|
|
|
|
for(size_t x : numbers)
|
|
|
|
@ -64,9 +66,32 @@ make_histogram(vector<double> numbers, size_t bin_count)
|
|
|
|
|
}
|
|
|
|
|
return bins;
|
|
|
|
|
}
|
|
|
|
|
void show_histogram_text(vector<size_t> bins, size_t bin_count)
|
|
|
|
|
{
|
|
|
|
|
size_t max_count = bins[0];
|
|
|
|
|
for(size_t x : bins)
|
|
|
|
|
{
|
|
|
|
|
if(x > max_count)
|
|
|
|
|
{
|
|
|
|
|
max_count = x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for(size_t i = 0;i<bin_count;i++){
|
|
|
|
|
size_t height = bins[i];
|
|
|
|
|
printf("%3d:", bins[i]);
|
|
|
|
|
if(max_count > MAX_ASTERISK)
|
|
|
|
|
height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
|
|
|
|
|
for(size_t 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,in.bin_count);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|