Родитель
393d659027
Сommit
fc08132081
@ -0,0 +1,3 @@
|
||||
10
|
||||
3 3 4 4 4 4 4 5 5 5
|
||||
3
|
@ -1,30 +1,31 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <math.h>
|
||||
#include "text.h"
|
||||
using namespace std;
|
||||
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
|
||||
void show_histogram_text(const std::vector<size_t> bins, size_t bin_count)
|
||||
void show_histogram_text(const std::vector<size_t> bins, size_t bin_count, const std::vector<double> numbers)
|
||||
{
|
||||
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++)
|
||||
size_t procent=100;
|
||||
for(size_t i = 0;i<(bin_count-1);i++){
|
||||
double number = numbers.size();
|
||||
//cout<<number;
|
||||
double proc=(bins[i]/number)*100;
|
||||
procent -=round(proc);
|
||||
printf("%3.0f%%:", proc);
|
||||
for(size_t j = 0;j<bins[i];j++)
|
||||
{
|
||||
cout<<"*";
|
||||
}
|
||||
cout<<endl;
|
||||
}
|
||||
//procent=Math.round(procent);
|
||||
printf("%3d%%:",procent);
|
||||
for(size_t j = 0;j<bins[bin_count - 1];j++)
|
||||
{
|
||||
cout<<"*";
|
||||
}
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче