|  |  | @ -4,82 +4,96 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | using namespace std; |  |  |  | using namespace std; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | int main() |  |  |  | struct Input { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | { |  |  |  |     vector<double> numbers; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     const size_t SCREEN_WIDTH = 80; |  |  |  |     size_t bin_count{}; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; |  |  |  | }; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | Input input_data() { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     Input in; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     int number_count; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     int number_count, bucket; |  |  |  |     do { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         cout << "Enter number count: "; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         cin >> number_count; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } while (number_count < 1); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     do |  |  |  |     do { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |         cout << "Enter bucket: "; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         cout << "Enter number count: "; cin >> number_count; |  |  |  |         cin >> in.bin_count; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } while (in.bin_count < 1); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     while (number_count < 1); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     do |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         cout << "Enter bucket: "; cin >> bucket; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     while (bucket < 1); |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     cout << "\n"; |  |  |  |     cout << "\n"; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     vector <double> numbers(number_count); |  |  |  |     in.numbers.resize(number_count); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     for (int i = 0; i < number_count; i++) cin >> numbers[i]; |  |  |  |     for (int i = 0; i < number_count; i++) { | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         cin >> in.numbers[i]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     float min = numbers[0]; |  |  |  |     return in; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     float max = numbers[0]; |  |  |  | } | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (float x : numbers) |  |  |  | void find_minmax(const vector<double>& numbers, double& min, double& max) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     min = numbers[0]; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     max = numbers[0]; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     for (float x : numbers) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (x < min) min = x; |  |  |  |         if (x < min) min = x; | 
			
		
	
		
		
			
				
					
					|  |  |  |         else if (x > max) max = x; |  |  |  |         else if (x > max) max = x; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     float k = (max-min)/bucket; |  |  |  | vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     double min, max; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     vector <int> stolb(bucket); |  |  |  |     find_minmax(numbers, min, max); | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (int j = 0; j < bucket; j++) stolb[j] = 0; |  |  |  |     float k = (max - min) / bin_count; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     vector<size_t> bins(bin_count, 0); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (int i = 0; i < number_count; i++) |  |  |  |     for (double number : numbers) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         bool flag = false; |  |  |  |         bool flag = false; | 
			
		
	
		
		
			
				
					
					|  |  |  |         for (int j = 0; (j < bucket && !flag); j++) |  |  |  |         for (size_t j = 0; (j < bin_count && !flag); j++) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         { |  |  |  |             if (number >= (min + k * j) && number < (min + k * (j + 1))) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             if (numbers[i] >= (min+k*j) && numbers[i] < (min+k*(1+j))) |  |  |  |                 bins[j]++; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 stolb[j]++; |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 flag = true; |  |  |  |                 flag = true; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (!flag) stolb[bucket-1]++; |  |  |  |         if (!flag) bins[bin_count - 1]++; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     int maxlen = 0; |  |  |  |     return bins; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | void show_histogram_text(const vector<size_t>& bins) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     const size_t SCREEN_WIDTH = 80; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (int j = 0; j < bucket; j++) |  |  |  |     size_t max_count = 0; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |     for (size_t count : bins) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if (maxlen<stolb[j]) maxlen = stolb[j]; |  |  |  |         if (count > max_count) { | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             max_count = count; | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     for (int j = 0; j < bucket; j++) |  |  |  |     for (size_t bin : bins) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     { |  |  |  |         if (bin < 100) cout << " "; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if (stolb[j] < 100) cout << " "; |  |  |  |         if (bin < 10) cout << " "; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if (stolb[j] < 10) cout << " "; |  |  |  |         cout << bin << "|"; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         cout << stolb[j] << "|"; |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         size_t height = stolb[j]; |  |  |  |         size_t height = bin; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if (maxlen > MAX_ASTERISK) |  |  |  |         if (max_count > MAX_ASTERISK) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         { |  |  |  |             if (max_count != bin) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             if (maxlen != stolb[j]) height = MAX_ASTERISK * (static_cast<float>(stolb[j])/maxlen); |  |  |  |                 height = MAX_ASTERISK * (static_cast<float>(bin) / max_count); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             else if (maxlen == stolb[j]) height = MAX_ASTERISK; |  |  |  |             else | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 height = MAX_ASTERISK; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         for (int i = 0; i < height; i++) cout << "*"; |  |  |  | 
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         for (size_t i = 0; i < height; i++) cout << "*"; | 
			
		
	
		
		
			
				
					
					|  |  |  |         cout << "\n"; |  |  |  |         cout << "\n"; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     return 0; |  |  |  | int main() { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     auto in = input_data(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     auto bins = make_histogram(in.numbers, in.bin_count); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     show_histogram_text(bins); | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |