|
|
|
@ -2,7 +2,9 @@
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include "histogram.h"
|
|
|
|
|
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
struct Input {
|
|
|
|
@ -10,6 +12,10 @@ struct Input {
|
|
|
|
|
size_t bin_count{};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userdata) {
|
|
|
|
|
return size * nmemb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
input_data(istream& in){
|
|
|
|
|
size_t number_count;
|
|
|
|
@ -22,12 +28,43 @@ in >> cin.bin_count;
|
|
|
|
|
return cin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]){
|
|
|
|
|
// curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
|
if(argc>1){
|
|
|
|
|
cout<<argc<<argv;
|
|
|
|
|
Input
|
|
|
|
|
download(const string& address) {
|
|
|
|
|
stringstream buffer;
|
|
|
|
|
|
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
|
|
|
|
|
|
|
|
|
return input_data(buffer, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
|
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
|
|
|
|
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
|
|
|
|
|
(*buffer).write(items, data_size);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]){
|
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
|
CURL *curl = curl_easy_init();
|
|
|
|
|
if(curl) {
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, "http://uit.mpei.ru/study/courses/cs/lab03/marks.txt");
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
|
|
|
|
|
curl_easy_perform(curl);
|
|
|
|
|
double speed;
|
|
|
|
|
curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &speed);
|
|
|
|
|
printf("Ñêîðîñòü çàãðóçêè ôàéëà: %.2f bytes/sec", speed);
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
}
|
|
|
|
|
Input input;
|
|
|
|
|
if (argc > 1) {
|
|
|
|
|
input = download(argv[1]);
|
|
|
|
|
} else {
|
|
|
|
|
input = input_data(cin, true);
|
|
|
|
|
}
|
|
|
|
|
auto in = input_data(cin);
|
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
show_histogram(bins, in.bin_count);
|
|
|
|
|