Сommit
						e3dc9d971f
					
				@ -0,0 +1,43 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
 | 
				
			||||||
 | 
					<CodeBlocks_project_file>
 | 
				
			||||||
 | 
						<FileVersion major="1" minor="6" />
 | 
				
			||||||
 | 
						<Project>
 | 
				
			||||||
 | 
							<Option title="labory1" />
 | 
				
			||||||
 | 
							<Option pch_mode="2" />
 | 
				
			||||||
 | 
							<Option compiler="gcc" />
 | 
				
			||||||
 | 
							<Build>
 | 
				
			||||||
 | 
								<Target title="Debug">
 | 
				
			||||||
 | 
									<Option output="bin/Debug/labory1" 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/labory1" 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=".gitignore">
 | 
				
			||||||
 | 
								<Option target="<{~None~}>" />
 | 
				
			||||||
 | 
							</Unit>
 | 
				
			||||||
 | 
							<Unit filename="main.cpp" />
 | 
				
			||||||
 | 
							<Extensions>
 | 
				
			||||||
 | 
								<lib_finder disable_auto="1" />
 | 
				
			||||||
 | 
							</Extensions>
 | 
				
			||||||
 | 
						</Project>
 | 
				
			||||||
 | 
					</CodeBlocks_project_file>
 | 
				
			||||||
@ -0,0 +1,95 @@
 | 
				
			|||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <cmath>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					using namespace std;
 | 
				
			||||||
 | 
					int main()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    size_t count, bin_count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    size_t i, j;
 | 
				
			||||||
 | 
					    float min, max, bin_size;
 | 
				
			||||||
 | 
					    float low, hi;
 | 
				
			||||||
 | 
					    cerr << "Count= ";
 | 
				
			||||||
 | 
					    cin >> count;
 | 
				
			||||||
 | 
					    cerr << "Bin_count= ";
 | 
				
			||||||
 | 
					    cin >> bin_count;
 | 
				
			||||||
 | 
					    vector<double>numbers(count);
 | 
				
			||||||
 | 
					    vector<size_t>bins(bin_count);
 | 
				
			||||||
 | 
					    for (i = 0; i < count; i++)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        cin >> numbers[i];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    min = numbers[0];
 | 
				
			||||||
 | 
					    max = numbers[0];
 | 
				
			||||||
 | 
					    for (i = 0; i < count; i++)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if (numbers[i] > max)
 | 
				
			||||||
 | 
					            max = numbers[i];
 | 
				
			||||||
 | 
					        if (numbers[i] < min)
 | 
				
			||||||
 | 
					            min = numbers[i];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    bin_size = (max - min) / bin_count;
 | 
				
			||||||
 | 
					    low = min;
 | 
				
			||||||
 | 
					    hi = low + bin_size;
 | 
				
			||||||
 | 
					    for (i = 0; i < count; i++)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        bool found = false;
 | 
				
			||||||
 | 
					        for (j = 0; (j < bin_count - 1) && !found; j++)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            low = min + j * bin_size;
 | 
				
			||||||
 | 
					            hi = min + (j + 1) * bin_size;
 | 
				
			||||||
 | 
					            if ((low <= numbers[i]) && (numbers[i] < hi))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                bins[j]++;
 | 
				
			||||||
 | 
					                found = true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (found == false)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            bins[bin_count - 1]++;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    size_t sum_bins = 0;
 | 
				
			||||||
 | 
					    for (size_t bin : bins)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        sum_bins += bin;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    size_t sred_bin = sum_bins / bin_count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const size_t SCREEN_WIDTH = 80;
 | 
				
			||||||
 | 
					    const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    size_t max_bin = bins[0];
 | 
				
			||||||
 | 
					    for (size_t bin : bins)
 | 
				
			||||||
 | 
					        if (bin > max_bin)
 | 
				
			||||||
 | 
					            max_bin = bin;
 | 
				
			||||||
 | 
					    for (size_t bin : bins)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        int height = bin;
 | 
				
			||||||
 | 
					        if (max_bin > MAX_ASTERISK)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            height = MAX_ASTERISK * (static_cast<double>(bin) / max_bin);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (bin < 100)
 | 
				
			||||||
 | 
					            cout << " ";
 | 
				
			||||||
 | 
					        if (bin < 10)
 | 
				
			||||||
 | 
					            cout << " ";
 | 
				
			||||||
 | 
					        cout << bin << "|";
 | 
				
			||||||
 | 
					        if (height > sred_bin) {
 | 
				
			||||||
 | 
					            for (size_t i = 0; i < sred_bin; i++)
 | 
				
			||||||
 | 
					                cout << "*";
 | 
				
			||||||
 | 
					            for (size_t i = sred_bin; i < height; i++)
 | 
				
			||||||
 | 
					                cout << "+";
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					            for (size_t i = 0; i < height; i++)
 | 
				
			||||||
 | 
					                cout << "*";
 | 
				
			||||||
 | 
					            for (size_t i = height; i < sred_bin; i++)
 | 
				
			||||||
 | 
					                cout << "-";
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        cout << endl;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
					Загрузка…
					
					
				
		Ссылка в новой задаче