Сравнить коммиты
Ничего общего в коммитах. '63de96b3feaa8b4fd10cbac30a211ebfdbde5cb9' и 'b6ad415c0e9264f4d7ae941e10b7e356c255d761' имеют совершенно разные истории.
63de96b3fe
...
b6ad415c0e
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -1,50 +1,102 @@
|
|||||||
#include "histogram.h"
|
#include <iostream>
|
||||||
#include "svg.h"
|
#include <vector>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
struct Input {
|
int main()
|
||||||
vector<double> numbers;
|
|
||||||
size_t bin_count{};
|
|
||||||
};
|
|
||||||
|
|
||||||
Input
|
|
||||||
input_data(istream& inn, bool prompt)
|
|
||||||
{
|
{
|
||||||
size_t number_count;
|
size_t numbers, columns, count;
|
||||||
if (prompt == true)
|
float minn, maxx, diff, lo, hi;
|
||||||
cerr << "number_count = ";
|
|
||||||
inn >> number_count;
|
cerr << "Quantity of numbers = "; cin >> numbers;
|
||||||
|
vector<float> xs(numbers);
|
||||||
Input in;
|
cerr << "Enter your numbers: ";
|
||||||
in.numbers.resize(number_count);
|
|
||||||
|
for (int i = 0; i < numbers; ++i)
|
||||||
if (prompt == true)
|
{
|
||||||
cerr << "numbers:";
|
cin >> xs[i];
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
|
||||||
inn >> in.numbers[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cerr << "columns = ";
|
cerr << "Columns = "; cin >> columns;
|
||||||
cin >> in.bin_count;
|
vector<size_t> a(columns);
|
||||||
return in;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
maxx = xs[0];
|
||||||
main(int argc, char* argv[])
|
minn = xs[0];
|
||||||
{
|
for (int i = 0; i < numbers; i++)
|
||||||
if (argc > 1)
|
{
|
||||||
{
|
if (xs[i] > maxx)
|
||||||
cerr << argc;
|
maxx = xs[i];
|
||||||
for(int i = 0; i < argc; i++){
|
else
|
||||||
cerr << "argv[" << i << "] = " << argv[i];
|
{
|
||||||
}
|
if (xs[i] < minn)
|
||||||
return 0;
|
minn = xs[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
diff = (maxx - minn) / columns;
|
||||||
|
lo = minn;
|
||||||
|
|
||||||
|
size_t max_count = 0;
|
||||||
|
for (int i = 0; i < columns; ++i)
|
||||||
|
{
|
||||||
|
count = 0;
|
||||||
|
|
||||||
auto in = input_data(cin, true);
|
if (i != columns - 1)
|
||||||
|
{
|
||||||
|
hi = lo + diff;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hi = maxx;
|
||||||
|
}
|
||||||
|
for (int j = 0; j < numbers; j++)
|
||||||
|
{
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
if ((xs[j] >= lo) && (xs[j] <= hi))
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
else
|
||||||
|
{
|
||||||
|
if ((xs[j] > lo) && (xs[j] <= hi))
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a[i] = count;
|
||||||
|
lo = hi;
|
||||||
|
|
||||||
show_histogram_svg(bins);
|
if (max_count < a[i])
|
||||||
|
max_count = a[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t SCREEN_WIDTH = 80;
|
||||||
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||||
|
size_t height;
|
||||||
|
for (int i = 0; i < columns; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (a[i] == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (a[i] < 10)
|
||||||
|
cout << " ";
|
||||||
|
else
|
||||||
|
if (a[i] < 100)
|
||||||
|
cout << " ";
|
||||||
|
|
||||||
|
cout << a[i] << "|";
|
||||||
|
|
||||||
|
if (max_count > MAX_ASTERISK)
|
||||||
|
height = MAX_ASTERISK * (static_cast<double>(a[i]) / max_count);
|
||||||
|
else
|
||||||
|
height = a[i];
|
||||||
|
|
||||||
|
for (int j = 0; j < height; j++)
|
||||||
|
{
|
||||||
|
cout << "*";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Загрузка…
Ссылка в новой задаче