Сравнить коммиты
Ничего общего в коммитах. '4574a4c9760866adec11ff4feefaba9f94902329' и 'ed1d3a38c3b0f5bf262c6a978d9e5e4f5195b36a' имеют совершенно разные истории.
4574a4c976
...
ed1d3a38c3
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -1,43 +1,98 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "histogram.h"
|
|
||||||
#include "text.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const size_t SCREEN_WIDTH = 80;
|
const size_t SCREEN_WIDTH = 80;
|
||||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||||
|
|
||||||
struct
|
void printspace (int number)
|
||||||
Input {
|
|
||||||
vector<double> numbers;
|
|
||||||
size_t bin_count{};
|
|
||||||
};
|
|
||||||
|
|
||||||
Input
|
|
||||||
input_data ()
|
|
||||||
{
|
{
|
||||||
Input in;
|
if (number < 10) cout << " ";
|
||||||
|
else if (number < 100) cout << " ";
|
||||||
cin >> in.bin_count;
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
cerr << "enter number count: ";
|
cerr << "enter number count: ";
|
||||||
cin >> number_count;
|
cin >> number_count;
|
||||||
|
|
||||||
in.numbers.resize(number_count);
|
vector<double> numbers(number_count);
|
||||||
for (size_t i=0; i<number_count; i++)
|
for (size_t i=0; i<number_count; i++)
|
||||||
{
|
{
|
||||||
cerr << "enter number" << (i+1) << ": ";
|
cerr << "enter number" << (i+1) << ": ";
|
||||||
cin >> in.numbers[i];
|
cin >> numbers[i];
|
||||||
}
|
}
|
||||||
return in;
|
size_t bin_count;
|
||||||
}
|
cerr << "enter bin count: ";
|
||||||
|
cin >> bin_count;
|
||||||
|
|
||||||
int
|
vector<size_t> bins(bin_count);
|
||||||
main()
|
|
||||||
{
|
double min = numbers[0];
|
||||||
auto in = input_data();
|
double max = numbers[0];
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
for (double x : numbers)
|
||||||
show_histogram_text(bins, in.bin_count);
|
{
|
||||||
|
if (x<min)
|
||||||
|
{
|
||||||
|
min=x;
|
||||||
|
}
|
||||||
|
else if (x>max)
|
||||||
|
{
|
||||||
|
max=x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double bin_size = (max - min) / bin_count;
|
||||||
|
|
||||||
|
size_t max_count = 0;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < number_count; i++)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
|
||||||
|
{
|
||||||
|
auto lo = min + j * bin_size;
|
||||||
|
auto hi = min + (j + 1) * bin_size;
|
||||||
|
if ((lo <= numbers[i]) && (numbers[i] < hi))
|
||||||
|
{
|
||||||
|
bins[j]++;
|
||||||
|
if (bins[j] > max_count)
|
||||||
|
{
|
||||||
|
max_count = bins[j];
|
||||||
|
}
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
bins[bin_count - 1]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max_count <= 76)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < bin_count; i++)
|
||||||
|
{
|
||||||
|
printspace(bins[i]);
|
||||||
|
cout << bins[i] << "|";
|
||||||
|
for (size_t j = 0; j < bins[i]; j++)
|
||||||
|
{
|
||||||
|
cout << "*";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < bin_count; i++){
|
||||||
|
size_t height = 76 * (static_cast<double>(bins[i]) / max_count);
|
||||||
|
printSpace(bins[i]);
|
||||||
|
cout << bins[i] << "|";
|
||||||
|
for (size_t j = 0; j < height; j++)
|
||||||
|
{
|
||||||
|
cout << "*";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
}
|
}
|
||||||
|
Загрузка…
Ссылка в новой задаче