code: point 2 add show_histogramm_text
Этот коммит содержится в:
47
main.cpp
47
main.cpp
@@ -3,6 +3,9 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
|
||||
struct
|
||||
Input {
|
||||
vector<double> numbers;
|
||||
@@ -70,37 +73,25 @@ make_histogram(std::vector<double> numbers, size_t bin_count){
|
||||
return bins;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
auto in = input_data();
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
|
||||
double min;
|
||||
double max;
|
||||
find_minmax(in.numbers, min, max);
|
||||
void
|
||||
show_histogramm_text(vector<int> bins, vector<double> numbers, size_t bin_count){
|
||||
|
||||
size_t max_count;
|
||||
for (int i =0; i<in.bin_count;i++){
|
||||
if (in.numbers[i]>max_count){
|
||||
max_count=in.numbers[i];
|
||||
for (int i =0; i<bin_count;i++){
|
||||
if (numbers[i]>max_count){
|
||||
max_count=numbers[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i =0; i<in.bin_count;i++){
|
||||
for (int i =0; i<bin_count;i++){
|
||||
if (bins[i]>max_count){
|
||||
max_count=bins[i];
|
||||
}
|
||||
}
|
||||
|
||||
//*cout<<max_count<<endl;
|
||||
|
||||
if (max_count>MAX_ASTERISK){
|
||||
for (int i=0; i<in.bin_count; i++){
|
||||
for (int i=0; i<bin_count; i++){
|
||||
size_t height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
|
||||
if (bins[i]<10){
|
||||
cout<<" "<<bins[i]<<"|";
|
||||
@@ -126,7 +117,7 @@ main()
|
||||
|
||||
}
|
||||
}else{
|
||||
for (int i=0; i<in.bin_count; i++){
|
||||
for (int i=0; i<bin_count; i++){
|
||||
if (bins[i]<10){
|
||||
cout<<" "<<bins[i]<<"|";
|
||||
for (int j=0;j<bins[i];j++){
|
||||
@@ -151,9 +142,19 @@ main()
|
||||
|
||||
}
|
||||
}
|
||||
for (int i =0; i< in.bin_count;i++){
|
||||
cout<<bins[i]<<" ";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
|
||||
auto in = input_data();
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
double min;
|
||||
double max;
|
||||
find_minmax(in.numbers, min, max);
|
||||
show_histogramm_text(bins, in.numbers, in.bin_count);
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user