diff --git a/main.cpp b/main.cpp index e929184..12c0c1d 100644 --- a/main.cpp +++ b/main.cpp @@ -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; } diff --git a/marks.txt b/marks.txt new file mode 100644 index 0000000..2cdb9aa --- /dev/null +++ b/marks.txt @@ -0,0 +1,3 @@ +10 +3 3 4 4 4 4 4 5 5 5 +3 diff --git a/svg.cpp b/svg.cpp index 898dc45..72de81b 100644 --- a/svg.cpp +++ b/svg.cpp @@ -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(); } diff --git a/svg.h b/svg.h index 1242c0e..c9e4a8e 100644 --- a/svg.h +++ b/svg.h @@ -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 diff --git a/text.cpp b/text.cpp index 3ce093a..4f5f3a8 100644 --- a/text.cpp +++ b/text.cpp @@ -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<<"*"; + } } diff --git a/text.h b/text.h index c7f792a..363afb1 100644 --- a/text.h +++ b/text.h @@ -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