Сравнить коммиты
3 Коммитов
c905ba9af5
...
3de94b2167
| Автор | SHA1 | Дата | |
|---|---|---|---|
| 3de94b2167 | |||
| f57b8d8043 | |||
| 8a7ae9dda2 |
@@ -1,9 +1,13 @@
|
||||
#include <curl/curl.h>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
#include "svg.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
@@ -12,35 +16,78 @@ struct Input {
|
||||
size_t bin_count{};
|
||||
};
|
||||
|
||||
size_t
|
||||
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
||||
size_t data_size = item_size * item_count;
|
||||
|
||||
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
|
||||
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
||||
|
||||
return data_size;
|
||||
}
|
||||
|
||||
|
||||
Input
|
||||
input_data()
|
||||
input_data(istream& in, bool prompt)
|
||||
{
|
||||
|
||||
size_t number_count;
|
||||
if(prompt)
|
||||
cerr << "count=";
|
||||
cin >> number_count;
|
||||
size_t number_count;
|
||||
in >> number_count;
|
||||
|
||||
Input in;
|
||||
Input rez;
|
||||
|
||||
in.numbers.resize(number_count);
|
||||
if(prompt)
|
||||
cerr << "numbers= ";
|
||||
rez.numbers.resize(number_count);
|
||||
|
||||
for (size_t i = 0; i < number_count; i++) {
|
||||
cin >> in.numbers[i];
|
||||
}
|
||||
|
||||
cerr << "bin_count= ";
|
||||
cin >> in.bin_count;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
for (size_t i = 0; i < number_count; i++)
|
||||
{
|
||||
in >> rez.numbers[i];
|
||||
}
|
||||
if(prompt)
|
||||
cerr << "bin_count= ";
|
||||
in >> rez.bin_count;
|
||||
return rez;
|
||||
}
|
||||
|
||||
auto in = input_data();
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
show_histogram_svg(bins);
|
||||
Input
|
||||
download(const string& address) {
|
||||
stringstream buffer;
|
||||
|
||||
CURL* curl = curl_easy_init();
|
||||
if(curl)
|
||||
{
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
if (res != 0)
|
||||
{
|
||||
cout << curl_easy_strerror(res);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
return input_data(buffer, false);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
|
||||
Input input;
|
||||
if (argc > 1) {
|
||||
input = download(argv[1]);
|
||||
} else {
|
||||
input = input_data(cin, true);
|
||||
}
|
||||
|
||||
|
||||
auto bins = make_histogram(input.numbers, input.bin_count);
|
||||
double ttt=0.0;
|
||||
show_histogram_svg(bins,ttt);
|
||||
/* show_histogram_text(bins, in.bin_count);*/
|
||||
|
||||
return 0;
|
||||
|
||||
Ссылка в новой задаче
Block a user