|  |  | @ -6,67 +6,97 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | 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; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  int main() { |  |  |  | struct Input | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     size_t number_count; |  |  |  | { | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     vector<double> numbers; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     size_t bin_count{}; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | }; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |      cerr << "Enter number count: "; |  |  |  | Input input_data() | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     Input in; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     size_t number_count; | 
			
		
	
		
		
			
				
					
					|  |  |  |     cin >> number_count; |  |  |  |     cin >> number_count; | 
			
		
	
		
		
			
				
					
					|  |  |  |     vector<double> numbers(number_count); |  |  |  |     in.numbers.resize(number_count); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     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.bin_count; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     return in; | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |      double min = numbers[0]; |  |  |  | void find_minmax(const vector<double> &numbers, double &min, double &max) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     double max = numbers[0]; |  |  |  | { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     for (double x : numbers) { |  |  |  |     min = numbers[0]; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if (x < min) { |  |  |  |     max = numbers[0]; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             min = x; |  |  |  |     for (auto el : numbers) | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (el > max) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             max = el; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         if (el < min) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             min = el; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         else if (x > max) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             max = x; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  |     double bin_count; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     cerr << "Enter bin count: "; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     cin >> bin_count; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     vector<size_t> bins(bin_count); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     double bin_size = (max - min) / bin_count; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (size_t i = 0; i < number_count; i++) { |  |  |  | vector<size_t> make_histogram(const vector<double> &numbers, const size_t &bin_count){ | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         vector<size_t> bins(bin_count); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         double max, min; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         find_minmax(numbers, min, max); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         double binSize = (max - min) / bin_count; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         for (size_t i = 0; i < numbers.size(); i++) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         { | 
			
		
	
		
		
			
				
					
					|  |  |  |             bool found = false; |  |  |  |             bool found = false; | 
			
		
	
		
		
			
				
					
					|  |  |  |         for (size_t j = 0; (j < bin_count - 1) && !found; j++) { |  |  |  |             for (size_t j = 0; (j < bin_count - 1) && !found; j++) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             auto lo = min + j * bin_size; |  |  |  |             { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             auto hi = min + (j + 1) * bin_size; |  |  |  |                 auto lo = min + j * binSize; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             if ((lo <= numbers[i]) && (numbers[i] < hi)) { |  |  |  |                 auto hi = min + (j + 1) * binSize; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 if ((lo <= numbers[i]) && (numbers[i] < hi)) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     bins[j]++; |  |  |  |                     bins[j]++; | 
			
		
	
		
		
			
				
					
					|  |  |  |                     found = true; |  |  |  |                     found = true; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (!found) { |  |  |  |             if (!found) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 bins[bin_count - 1]++; |  |  |  |                 bins[bin_count - 1]++; | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |         return bins; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |      size_t max_bin = bins[0]; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (size_t i = 1; i < bin_count; i++){ |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (bins[i] > max_bin) max_bin = bins[i]; |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |      size_t bin; |  |  |  | void show_histogram_text(const vector<size_t> &bins){ | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     size_t height; |  |  |  |         size_t maxCount = bins[0]; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     for (size_t i = 0; i < bin_count; i++){ |  |  |  |         for (auto bin : bins) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         bin = bins[i]; |  |  |  |         { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if (bin < 100) cout << " "; |  |  |  |             if (maxCount < bin) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if (bin < 10) cout << " "; |  |  |  |             { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if (max_bin > MAX_ASTERISK) height = MAX_ASTERISK * (static_cast<double>(bin) / max_bin); |  |  |  |                 maxCount = bin; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         else height = bin; |  |  |  |             } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         cout << bin << "|"; |  |  |  |         } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         for (size_t j = 0; j < height; j++){ |  |  |  |         for (auto bin : bins) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             cout << "*"; |  |  |  |         { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |             if (bin < 100) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         cout<<endl; |  |  |  |             { | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 cout << " "; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             if (bin < 10) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 cout << " "; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             size_t height = maxCount < MAX_ASTERISK ? bin : MAX_ASTERISK * (static_cast<double>(bin) / maxCount); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             cout << bin << "|" << string(height, '*'); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             cout << "\n"; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | int main() { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     Input in = input_data(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     auto bins = make_histogram(in.numbers, in.bin_count); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     show_histogram_text(bins); | 
			
		
	
		
		
			
				
					
					|  |  |  |     return 0; |  |  |  |     return 0; | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } |