|  |  | @ -1,19 +1,21 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | #include <iostream> |  |  |  | #include <iostream> | 
			
		
	
		
		
			
				
					
					|  |  |  | #include <vector> |  |  |  | #include <vector> | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | #include "histogram.h" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | #include "svg.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; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | using namespace std; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | struct Input |  |  |  | struct Input | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |     vector<double> numbers; |  |  |  |     vector<double> numbers; | 
			
		
	
		
		
			
				
					
					|  |  |  |     size_t bin_count{}; |  |  |  |     size_t bin_count{}; | 
			
		
	
		
		
			
				
					
					|  |  |  | }; |  |  |  | }; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | int main() |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | Input input_data() |  |  |  | Input input_data() | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -27,109 +29,23 @@ Input input_data() | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     cerr << "Enter numbers: "; |  |  |  |     cerr << "Enter numbers: "; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     vector<double> numbers(number_count); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     // vector<double> numbers(number_count);
 |  |  |  |     // vector<double> numbers(number_count);
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (int i = 0; i < number_count; i++) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (size_t i = 0; i < number_count; i++) |  |  |  |     for (size_t i = 0; i < number_count; i++) | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     { | 
			
		
	
		
		
			
				
					
					|  |  |  |         cin >> numbers[i]; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         cin >> in.numbers[i]; |  |  |  |         cin >> in.numbers[i]; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     cerr << "Enter bin count: "; |  |  |  |     cerr << "Count of baskets: "; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     cin >> bin_count; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     cerr << " number of baskets: "; |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     cin >> in.bin_count; |  |  |  |     cin >> in.bin_count; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     vector<double> bins(bin_count); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     vector<int> count(number_count); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     vector<double> height(bin_count); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     return in; |  |  |  |     return in; | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | using namespace std; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     int max_count = bins[0]; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     double min = numbers[0]; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     double max = numbers[0]; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | void find_minmax(const vector<double> &numbers, double &min, double &max) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     min = numbers[0]; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (double x : numbers) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | @ -46,32 +55,44 @@ int main() |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             max = x; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     double bin_size = (max - min) / bin_count; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | int main() |  |  |  | int main() | 
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |     Input in = input_data(); |  |  |  |     auto in = input_data(); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     auto bins = make_histogram(in.numbers, in.bin_count); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     for (size_t i = 0; i < number_count; i++) |  |  |  |     show_histogram_svg(bins); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     vector<int> bins(in.bin_count); |  |  |  |     return 0; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     vector<double> height(in.bin_count); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     int max_count = bins[0]; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     double min = in.numbers[0]; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     double max = in.numbers[0]; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     find_minmax(in.numbers, min, max); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     double bin_size = (max - min) / in.bin_count; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (size_t i = 0; i < in.numbers.size(); i++) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         bool found = false; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         for (size_t j = 0; (j < bin_count - 1) && !found; j++) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         for (size_t j = 0; (j < in.bin_count - 1) && !found; j++) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             auto lo = min + j * bin_size; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             auto hi = min + (j + 1) * bin_size; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             if ((lo <= numbers[i]) && (numbers[i] < hi)) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             if ((lo <= in.numbers[i]) && (in.numbers[i] < hi)) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 bins[j]++; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 count[j]++; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 found = true; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (!found ) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (!found) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             bins[bin_count - 1]++; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             count[bin_count - 1]++; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             bins[in.bin_count - 1]++; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (int i = 0; i < bin_count; i++) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (int i = 0; i < in.bin_count; i++) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (bins[i] > max_count) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | @ -79,12 +100,17 @@ int main() |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (int i = 0; i < bin_count; i++) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (int i = 0; i < in.bin_count; i++) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         height[i] = (MAX_ASTERISK * count[i]) / max_count; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (bins[i] > MAX_ASTERISK) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             height[i] = (MAX_ASTERISK * bins[i]) / max_count; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         else |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             height[i] = bins[i]; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (int i = 0; i < bin_count; i++) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (int i = 0; i < in.bin_count; i++) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (bins[i] < 100) |  |  |  |  | 
			
		
	
	
		
		
			
				
					|  |  | 
 |