code: last
Этот коммит содержится в:
14
main.cpp
14
main.cpp
@@ -6,14 +6,14 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
struct Input {
|
struct Input {
|
||||||
std::vector<double> numbers;
|
std::vector<double> numbers;
|
||||||
size_t bin_count{};
|
|
||||||
size_t number_count{};
|
size_t number_count{};
|
||||||
|
size_t bin_count{};
|
||||||
};
|
};
|
||||||
Input
|
Input
|
||||||
input_data() {
|
input_data() {
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
cin >> number_count;
|
|
||||||
Input in;
|
Input in;
|
||||||
|
cin >> number_count;
|
||||||
in.numbers.resize(number_count);
|
in.numbers.resize(number_count);
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
cin >> in.numbers[i];
|
cin >> in.numbers[i];
|
||||||
@@ -26,6 +26,14 @@ int main()
|
|||||||
{
|
{
|
||||||
auto in = input_data();
|
auto in = input_data();
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
3
marks.txt
Обычный файл
3
marks.txt
Обычный файл
@@ -0,0 +1,3 @@
|
|||||||
|
10
|
||||||
|
3 3 4 4 4 4 4 5 5 5
|
||||||
|
3
|
||||||
56
svg.cpp
56
svg.cpp
@@ -5,50 +5,44 @@ using namespace std;
|
|||||||
|
|
||||||
void
|
void
|
||||||
svg_begin(double width, double height) {
|
svg_begin(double width, double height) {
|
||||||
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
std::cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||||
cout << "<svg ";
|
std::cout << "<svg ";
|
||||||
cout << "width='" << width << "' ";
|
std::cout << "width='" << width << "' ";
|
||||||
cout << "height='" << height << "' ";
|
std::cout << "height='" << height << "' ";
|
||||||
cout << "viewBox='0 0 " << width << " " << height << "' ";
|
std::cout << "viewBox='0 0 " << width << " " << height << "' ";
|
||||||
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
|
std::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>";
|
|
||||||
}
|
|
||||||
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";
|
|
||||||
}
|
|
||||||
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_end() {
|
|
||||||
cout << "</svg>\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
show_histogram_svg(const vector<size_t> bins) {
|
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,std::string stroke = "black", std::string fil = "black"){
|
||||||
|
std::cout<< "<rect x='"<< x <<"' y='"<< y <<"' width='"<< width <<"' height='"<< height <<"' />";
|
||||||
|
}
|
||||||
|
void
|
||||||
|
svg_end() {
|
||||||
|
std::cout << "</svg>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
show_histogram_svg(std::vector<size_t> bins,size_t max_count) {
|
||||||
const auto IMAGE_WIDTH = 400;
|
const auto IMAGE_WIDTH = 400;
|
||||||
const auto IMAGE_HEIGHT = 300;
|
const auto IMAGE_HEIGHT = 300;
|
||||||
const auto TEXT_LEFT = 20;
|
const auto TEXT_LEFT = 20;
|
||||||
const auto TEXT_BASELINE = 20;
|
const auto TEXT_BASELINE = 20;
|
||||||
const auto TEXT_WIDTH = 50;
|
const auto TEXT_WIDTH = 50;
|
||||||
const auto BIN_HEIGHT = 30;
|
const auto BIN_HEIGHT = 30;
|
||||||
const auto BLOCK_WIDTH = 10;
|
const auto BLOCK_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH)/max_count;
|
||||||
svg_begin(400, 300);
|
|
||||||
// svg_rect(50, 0,bins[0] * 10, 30);
|
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||||
svg_text(20, 20, to_string(bins[0]));
|
|
||||||
svg_end();
|
|
||||||
|
|
||||||
double top = 0;
|
double top = 0;
|
||||||
for (size_t bin : bins) {
|
for (size_t bin : bins) {
|
||||||
const double bin_width = BLOCK_WIDTH * bin;
|
const double bin_width = BLOCK_WIDTH * bin;
|
||||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));
|
||||||
// svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
||||||
top += BIN_HEIGHT;
|
top += BIN_HEIGHT;
|
||||||
}
|
}
|
||||||
svg_rect(0, 0, 100, 200, "blue", "#aaffaa");
|
svg_end();
|
||||||
}
|
}
|
||||||
|
|||||||
4
svg.h
4
svg.h
@@ -2,9 +2,9 @@
|
|||||||
#define SVG_H_INCLUDED
|
#define SVG_H_INCLUDED
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
void
|
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
|
#endif // SVG_H_INCLUDED
|
||||||
|
|||||||
31
text.cpp
31
text.cpp
@@ -1,30 +1,31 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <math.h>
|
||||||
#include "text.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;
|
||||||
|
|
||||||
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];
|
size_t procent=100;
|
||||||
for(size_t x : bins)
|
for(size_t i = 0;i<(bin_count-1);i++){
|
||||||
{
|
double number = numbers.size();
|
||||||
if(x > max_count)
|
//cout<<number;
|
||||||
{
|
double proc=(bins[i]/number)*100;
|
||||||
max_count = x;
|
procent -=round(proc);
|
||||||
}
|
printf("%3.0f%%:", proc);
|
||||||
}
|
for(size_t j = 0;j<bins[i];j++)
|
||||||
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++)
|
|
||||||
{
|
{
|
||||||
cout<<"*";
|
cout<<"*";
|
||||||
}
|
}
|
||||||
cout<<endl;
|
cout<<endl;
|
||||||
}
|
}
|
||||||
|
//procent=Math.round(procent);
|
||||||
|
printf("%3d%%:",procent);
|
||||||
|
for(size_t j = 0;j<bins[bin_count - 1];j++)
|
||||||
|
{
|
||||||
|
cout<<"*";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
text.h
2
text.h
@@ -5,6 +5,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void
|
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
|
#endif // TEXT_H_INCLUDED
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user