KhatyukhinYS 1 год назад
Родитель 393d659027
Сommit fc08132081

@ -6,14 +6,14 @@
using namespace std;
struct Input {
std::vector<double> numbers;
size_t bin_count{};
size_t number_count{};
size_t bin_count{};
};
Input
input_data() {
size_t number_count;
cin >> number_count;
Input in;
cin >> number_count;
in.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++) {
cin >> in.numbers[i];
@ -26,6 +26,14 @@ int main()
{
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins);
//show_histogram_text(bins,in.bin_count,in.numbers);
auto max_count=bins[0];
for(size_t x : bins){
if (x > max_count)
{
max_count=x;
}
}
show_histogram_svg(bins, max_count);
return 0;
}

@ -0,0 +1,3 @@
10
3 3 4 4 4 4 4 5 5 5
3

@ -5,50 +5,44 @@ using namespace std;
void
svg_begin(double width, double height) {
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
cout << "<svg ";
cout << "width='" << width << "' ";
cout << "height='" << height << "' ";
cout << "viewBox='0 0 " << width << " " << height << "' ";
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
}
void
svg_text(double left, double baseline, string text) {
cout << "<text x='" << left << "' y='35'>anything you want</text>";
std::cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
std::cout << "<svg ";
std::cout << "width='" << width << "' ";
std::cout << "height='" << height << "' ";
std::cout << "viewBox='0 0 " << width << " " << height << "' ";
std::cout << "xmlns='http://www.w3.org/2000/svg'>\n";
}
void
svg_rect(double x, double y, double width, double height){
cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke ='cyan' fill='#fce156' />\n";
svg_text(double left, double baseline, std::string text) {
std::cout << "<text x='"<< left <<"' y='"<< baseline <<"'>"<< text <<"</text>";
}
void svg_rect(double x, double y, double width, double height,
string stroke = "black", string fill = "black"){
cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke ='cyan' fill='#fce166' />\n";
void svg_rect(double x, double y, double width, double height,std::string stroke = "black", std::string fil = "black"){
std::cout<< "<rect x='"<< x <<"' y='"<< y <<"' width='"<< width <<"' height='"<< height <<"' />";
}
void
svg_end() {
cout << "</svg>\n";
std::cout << "</svg>\n";
}
void
show_histogram_svg(const vector<size_t> bins) {
show_histogram_svg(std::vector<size_t> bins,size_t max_count) {
const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20;
const auto TEXT_BASELINE = 20;
const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10;
svg_begin(400, 300);
// svg_rect(50, 0,bins[0] * 10, 30);
svg_text(20, 20, to_string(bins[0]));
svg_end();
const auto BLOCK_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH)/max_count;
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
double top = 0;
for (size_t bin : bins) {
const double bin_width = BLOCK_WIDTH * bin;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
// svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
top += BIN_HEIGHT;
}
svg_rect(0, 0, 100, 200, "blue", "#aaffaa");
svg_end();
}

@ -2,9 +2,9 @@
#define SVG_H_INCLUDED
#include <iostream>
#include <vector>
using namespace std;
void
show_histogram_svg(std::vector<size_t> bins);
show_histogram_svg(std::vector<size_t> bins,size_t max_count);
#endif // SVG_H_INCLUDED

@ -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<<"*";
}
}

@ -5,6 +5,6 @@
#include <iostream>
void
show_histogram_text(const std::vector<size_t> bins, size_t bin_count);
show_histogram_text(const std::vector<size_t> bins, size_t bin_count,const std::vector<double> numbers);
#endif // TEXT_H_INCLUDED

Загрузка…
Отмена
Сохранить