Сommit
						e403ab8bdf
					
				@ -0,0 +1,40 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
 | 
				
			||||||
 | 
					<CodeBlocks_project_file>
 | 
				
			||||||
 | 
						<FileVersion major="1" minor="6" />
 | 
				
			||||||
 | 
						<Project>
 | 
				
			||||||
 | 
							<Option title="lab1" />
 | 
				
			||||||
 | 
							<Option pch_mode="2" />
 | 
				
			||||||
 | 
							<Option compiler="gcc" />
 | 
				
			||||||
 | 
							<Build>
 | 
				
			||||||
 | 
								<Target title="Debug">
 | 
				
			||||||
 | 
									<Option output="bin/Debug/lab1" prefix_auto="1" extension_auto="1" />
 | 
				
			||||||
 | 
									<Option object_output="obj/Debug/" />
 | 
				
			||||||
 | 
									<Option type="1" />
 | 
				
			||||||
 | 
									<Option compiler="gcc" />
 | 
				
			||||||
 | 
									<Compiler>
 | 
				
			||||||
 | 
										<Add option="-g" />
 | 
				
			||||||
 | 
									</Compiler>
 | 
				
			||||||
 | 
								</Target>
 | 
				
			||||||
 | 
								<Target title="Release">
 | 
				
			||||||
 | 
									<Option output="bin/Release/lab1" prefix_auto="1" extension_auto="1" />
 | 
				
			||||||
 | 
									<Option object_output="obj/Release/" />
 | 
				
			||||||
 | 
									<Option type="1" />
 | 
				
			||||||
 | 
									<Option compiler="gcc" />
 | 
				
			||||||
 | 
									<Compiler>
 | 
				
			||||||
 | 
										<Add option="-O2" />
 | 
				
			||||||
 | 
									</Compiler>
 | 
				
			||||||
 | 
									<Linker>
 | 
				
			||||||
 | 
										<Add option="-s" />
 | 
				
			||||||
 | 
									</Linker>
 | 
				
			||||||
 | 
								</Target>
 | 
				
			||||||
 | 
							</Build>
 | 
				
			||||||
 | 
							<Compiler>
 | 
				
			||||||
 | 
								<Add option="-Wall" />
 | 
				
			||||||
 | 
								<Add option="-fexceptions" />
 | 
				
			||||||
 | 
							</Compiler>
 | 
				
			||||||
 | 
							<Unit filename="main.cpp" />
 | 
				
			||||||
 | 
							<Extensions>
 | 
				
			||||||
 | 
								<lib_finder disable_auto="1" />
 | 
				
			||||||
 | 
							</Extensions>
 | 
				
			||||||
 | 
						</Project>
 | 
				
			||||||
 | 
					</CodeBlocks_project_file>
 | 
				
			||||||
@ -0,0 +1,75 @@
 | 
				
			|||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					#include <cmath>
 | 
				
			||||||
 | 
					using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(){
 | 
				
			||||||
 | 
					    const size_t SCREEN_WIDTH = 80;
 | 
				
			||||||
 | 
					    const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
 | 
				
			||||||
 | 
					    size_t number_count;
 | 
				
			||||||
 | 
					    cerr << "Enter amount of numbers \n";
 | 
				
			||||||
 | 
					    cin >> number_count;
 | 
				
			||||||
 | 
					    vector<double> numbers(number_count);
 | 
				
			||||||
 | 
					    for (size_t i = 0; i < number_count; i++){
 | 
				
			||||||
 | 
					        cerr << "Input number " << i+1 << endl;
 | 
				
			||||||
 | 
					        cin >> numbers[i];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    double minc, maxc;
 | 
				
			||||||
 | 
					    minc = maxc = numbers[0];
 | 
				
			||||||
 | 
					    for (size_t i = 1; i < number_count; i++ ){
 | 
				
			||||||
 | 
					        if(numbers[i] < minc){
 | 
				
			||||||
 | 
					            minc = numbers[i];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else if (numbers[i] > maxc){
 | 
				
			||||||
 | 
					            maxc = numbers[i];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    size_t bin_count;
 | 
				
			||||||
 | 
					    cerr << "Input number of bins \n";
 | 
				
			||||||
 | 
					    cin >> bin_count;
 | 
				
			||||||
 | 
					    vector<size_t> bins(bin_count);
 | 
				
			||||||
 | 
					    double bin_size = (maxc - minc) / bin_count;
 | 
				
			||||||
 | 
					    size_t bin_max_size = 0;
 | 
				
			||||||
 | 
					    for (size_t i = 0; i < number_count; i++) {
 | 
				
			||||||
 | 
					        bool found = false;
 | 
				
			||||||
 | 
					        for (size_t j = 0; (j < bin_count - 1) && !found; j++) {
 | 
				
			||||||
 | 
					            auto lo = minc + j * bin_size;
 | 
				
			||||||
 | 
					            auto hi = minc + (j + 1) * bin_size;
 | 
				
			||||||
 | 
					            if ((lo <= numbers[i]) && (numbers[i] < hi)) {
 | 
				
			||||||
 | 
					                bins[j]++;
 | 
				
			||||||
 | 
					                found = true;
 | 
				
			||||||
 | 
					                if (bins[j]> bin_max_size){
 | 
				
			||||||
 | 
					                    bin_max_size = bins[j];
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (!found) {
 | 
				
			||||||
 | 
					            bins[bin_count - 1]++;
 | 
				
			||||||
 | 
					            if (bins[bin_count - 1]> bin_max_size){
 | 
				
			||||||
 | 
					                    bin_max_size = bins[bin_count - 1];
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    size_t height;
 | 
				
			||||||
 | 
					    for(int i = 0; i<bin_count; i++){
 | 
				
			||||||
 | 
					        if(bins[i]<100){
 | 
				
			||||||
 | 
					            cout<<" ";
 | 
				
			||||||
 | 
					            if(bins[i]<10){
 | 
				
			||||||
 | 
					                cout<<" ";
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        cout<<bins[i]<<"|";
 | 
				
			||||||
 | 
					        if(bin_max_size >= MAX_ASTERISK){
 | 
				
			||||||
 | 
					            height = floor(static_cast<double>(bins[i])*76.0f/static_cast<double>(bin_max_size));
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            height = bins[i];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        for(int j = 0; j<height; j++){
 | 
				
			||||||
 | 
					            cout<<"*";
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        cout<<endl;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
					Загрузка…
					
					
				
		Ссылка в новой задаче