|  |  |  | @ -9,13 +9,14 @@ | 
			
		
	
		
			
				
					|  |  |  |  | #include <curl/curl.h> | 
			
		
	
		
			
				
					|  |  |  |  | #include <sstream> | 
			
		
	
		
			
				
					|  |  |  |  | #include <string> | 
			
		
	
		
			
				
					|  |  |  |  | #include <ctype.h> | 
			
		
	
		
			
				
					|  |  |  |  | using namespace std; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | struct Input { | 
			
		
	
		
			
				
					|  |  |  |  |     vector<double> numbers; | 
			
		
	
		
			
				
					|  |  |  |  |     size_t bin_count{}; | 
			
		
	
		
			
				
					|  |  |  |  | }; | 
			
		
	
		
			
				
					|  |  |  |  | Input input_data(istream& in,bool prompt) | 
			
		
	
		
			
				
					|  |  |  |  | Input input_data(istream& in,bool prompt, int bins_cht) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |     Input in_data; | 
			
		
	
		
			
				
					|  |  |  |  |     int number_count; | 
			
		
	
	
		
			
				
					|  |  |  | @ -25,8 +26,14 @@ Input input_data(istream& in,bool prompt) | 
			
		
	
		
			
				
					|  |  |  |  |     for (size_t i = 0; i < number_count; i++) { | 
			
		
	
		
			
				
					|  |  |  |  |         in >> in_data.numbers[i]; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     if (prompt)cerr << "Enter bin count: "; | 
			
		
	
		
			
				
					|  |  |  |  |     in >> in_data.bin_count; | 
			
		
	
		
			
				
					|  |  |  |  |     if (bins_cht == 0) | 
			
		
	
		
			
				
					|  |  |  |  |     { | 
			
		
	
		
			
				
					|  |  |  |  |         if (prompt)cerr << "Enter bin count: "; | 
			
		
	
		
			
				
					|  |  |  |  |         in >> in_data.bin_count; | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     else | 
			
		
	
		
			
				
					|  |  |  |  |         in_data.bin_count = bins_cht; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     return in_data; | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -37,7 +44,7 @@ static size_t write_data(void* items, size_t item_size, size_t item_count, void* | 
			
		
	
		
			
				
					|  |  |  |  |     buffer->write((char*)items, data_size); | 
			
		
	
		
			
				
					|  |  |  |  |     return data_size; | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | Input download(const string& address)  | 
			
		
	
		
			
				
					|  |  |  |  | Input download(const string& address, int bins_cht) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |     stringstream buffer; | 
			
		
	
		
			
				
					|  |  |  |  |     CURL* curl = curl_easy_init(); | 
			
		
	
	
		
			
				
					|  |  |  | @ -55,20 +62,56 @@ Input download(const string& address) | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         curl_easy_cleanup(curl); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     return input_data(buffer, false); | 
			
		
	
		
			
				
					|  |  |  |  |     return input_data(buffer, false, bins_cht); | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | bool IsAllDigits(string s) | 
			
		
	
		
			
				
					|  |  |  |  | {     | 
			
		
	
		
			
				
					|  |  |  |  |     for(char c : s) if (!isdigit(c)) return false; | 
			
		
	
		
			
				
					|  |  |  |  |     return true; | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | int main(int argc, char* argv[]) | 
			
		
	
		
			
				
					|  |  |  |  | { | 
			
		
	
		
			
				
					|  |  |  |  |     curl_global_init(CURL_GLOBAL_ALL); | 
			
		
	
		
			
				
					|  |  |  |  |     setlocale(LC_ALL, "Russian"); | 
			
		
	
		
			
				
					|  |  |  |  |     Input input; | 
			
		
	
		
			
				
					|  |  |  |  |     if (argc > 1) { | 
			
		
	
		
			
				
					|  |  |  |  |         input = download(argv[1]); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     else { | 
			
		
	
		
			
				
					|  |  |  |  |         input = input_data(cin, true); | 
			
		
	
		
			
				
					|  |  |  |  |     bool get_bins = false; | 
			
		
	
		
			
				
					|  |  |  |  |     int get_bins_pos = -1; | 
			
		
	
		
			
				
					|  |  |  |  |     int  bins_cnt = 0; | 
			
		
	
		
			
				
					|  |  |  |  |     string URL = ""; | 
			
		
	
		
			
				
					|  |  |  |  |     if (argc > 4) | 
			
		
	
		
			
				
					|  |  |  |  |     { | 
			
		
	
		
			
				
					|  |  |  |  |         cerr << "Количество параметров не должно превышать трех"; | 
			
		
	
		
			
				
					|  |  |  |  |         exit(1); | 
			
		
	
		
			
				
					|  |  |  |  |     }         | 
			
		
	
		
			
				
					|  |  |  |  |     if (argc > 1)  | 
			
		
	
		
			
				
					|  |  |  |  |     { | 
			
		
	
		
			
				
					|  |  |  |  |         for (int i = 1; i < argc; i++) | 
			
		
	
		
			
				
					|  |  |  |  |         { | 
			
		
	
		
			
				
					|  |  |  |  |             if (strcmp(argv[i], "-bins")==0) | 
			
		
	
		
			
				
					|  |  |  |  |             { | 
			
		
	
		
			
				
					|  |  |  |  |                 get_bins = true; | 
			
		
	
		
			
				
					|  |  |  |  |                 get_bins_pos = i; | 
			
		
	
		
			
				
					|  |  |  |  |             }                 | 
			
		
	
		
			
				
					|  |  |  |  |             else | 
			
		
	
		
			
				
					|  |  |  |  |                 if ((IsAllDigits(argv[i])) && (get_bins_pos == (i-1))) | 
			
		
	
		
			
				
					|  |  |  |  |                     bins_cnt = atoi(argv[i]); | 
			
		
	
		
			
				
					|  |  |  |  |                 else | 
			
		
	
		
			
				
					|  |  |  |  |                     URL = argv[i];                 | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         if (get_bins && (bins_cnt == 0)) | 
			
		
	
		
			
				
					|  |  |  |  |         { | 
			
		
	
		
			
				
					|  |  |  |  |             cerr << "После ключа -bins должно следовать натуральное число"; | 
			
		
	
		
			
				
					|  |  |  |  |             exit(1); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  |     if (URL == "") | 
			
		
	
		
			
				
					|  |  |  |  |         input = input_data(cin, true, bins_cnt); | 
			
		
	
		
			
				
					|  |  |  |  |     else | 
			
		
	
		
			
				
					|  |  |  |  |         input = download(URL, bins_cnt); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     auto bins = make_histogram(input.numbers, input.bin_count); | 
			
		
	
		
			
				
					|  |  |  |  |     show_histogram_svg(bins, input.numbers.size()); | 
			
		
	
		
			
				
					|  |  |  |  |     return 0; | 
			
		
	
	
		
			
				
					|  |  |  | 
 |