From 2177e78312b26e39fd208f34a53d0e46b73ca61f Mon Sep 17 00:00:00 2001 From: "Ivan (BeloziorovIA)" <BeloziorovIA@mpei.ru> Date: Mon, 2 Jun 2025 06:42:33 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=D1=81=20=D0=B1=D1=83=D1=84=D0=B5=D1=80=D0=BE=D0=BC,=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D1=80=D1=83=D0=B6=D0=B5=D0=BD=D0=BD=D1=8B=D0=BC=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=81=D0=B5=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/main.cpp b/main.cpp index d185251..774c343 100644 --- a/main.cpp +++ b/main.cpp @@ -7,6 +7,8 @@ #include "text.h" #include "svg.h" #include <curl/curl.h> +#include <sstream> +#include <string> using namespace std; @@ -50,36 +52,36 @@ Input input_data(istream& in, bool prompt) return stct; } -int main(int argc, char* argv[]) +Input +download(const string& address) { - curl_global_init(CURL_GLOBAL_ALL); + stringstream buffer; - if (argc > 1) + CURL *curl = curl_easy_init(); + if(curl) { - CURL *curl = curl_easy_init(); - if(curl) + CURLcode res; + curl_easy_setopt(curl, CURLOPT_URL, address.c_str()); + res = curl_easy_perform(curl); + if (res != CURLE_OK) { - CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, argv[1]); - res = curl_easy_perform(curl); - if (res != CURLE_OK){ - cerr << curl_easy_strerror(res); - exit(1); - } - curl_easy_cleanup(curl); + cerr << curl_easy_strerror(res); + exit(1); } - return 0; + curl_easy_cleanup(curl); } + return input_data(buffer, false); +} - //���� ������� � ���������� ������ - auto in = input_data(cin, true); - - //�������� ������� bins ��� ����������� - vector<size_t> bins = make_histogram(in.Numbers, in.bin_count); +int +main(int argc, char* argv[]) { + Input input; + if (argc > 1) { + input = download(argv[1]); + } else { + input = input_data(cin, true); + } - //����� ����������� + const auto bins = make_histogram(input.Numbers, input.bin_count); show_histogram_svg(bins); - //show_histogram_text(bins); - - return 0; }