Сравнить коммиты

..

Ничего общего в коммитах. '9ec235110ac14727cd747ebbaaa1888515a941ab' и '92a689e77796aadc9aaa1b1943f21f7dc9bbdb37' имеют совершенно разные истории.

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="lab01" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/lab01" 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/lab01" 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>

@ -3,29 +3,25 @@
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;
int main()
struct Input { {
vector<double> numbers;
size_t bin_count{};
};
Input
input_data() {
size_t number_count; size_t number_count;
cerr << "Enter number count: ";
cin >> number_count; cin >> number_count;
Input in;
in.numbers.resize(number_count); vector<double> numbers(number_count);
cerr << "Enter numbers: ";
for(size_t i = 0; i < number_count; i++){ for(size_t i = 0; i < number_count; i++){
cin >> in.numbers[i]; cin >> numbers[i];
}
cin >> in.bin_count;
return in;
} }
void size_t bin_count;
find_minmax(const vector<double>& numbers, double& min, double& max) { cerr << "Enter bin count: ";
min = numbers[0]; cin >> bin_count;
max = numbers[0];
double min = numbers[0];
double max = numbers[0];
/*
for (size_t x : numbers) { for (size_t x : numbers) {
if (x < min) { if (x < min) {
min = x; min = x;
@ -34,15 +30,18 @@ find_minmax(const vector<double>& numbers, double& min, double& max) {
max = x; max = x;
} }
} }
// (çäåñü êîä ïîèñêà ìèíèìóìà è ìàêñèìóìà) */
for (size_t i=1; i<number_count; i++){
if (numbers[i]<min){
min=numbers[i];
}
else if (numbers[i]>max){
max=numbers[i];
}
} }
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count){
vector<size_t> bins(bin_count); vector<size_t> bins(bin_count);
double min, max;
find_minmax(numbers, min, max);
double bin_size = (max-min)/bin_count; double bin_size = (max-min)/bin_count;
for (size_t i = 0; i < numbers.size(); i++) { for (size_t i = 0; i < number_count; 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 lo = min + j * bin_size;
@ -55,30 +54,26 @@ vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count){
if (!found) { if (!found) {
bins[bin_count-1]++; bins[bin_count-1]++;
} }
}
return bins;
}
void }
show_histogram_text(vector<size_t> bins){
size_t max_count = bins[0]; size_t max_count = bins[0];
for(size_t x: bins){ for(size_t x: bins){
if(x > max_count){ if(x > max_count){
max_count = x; max_count = x;
} }
} }
vector<size_t> heights(bins.size()); vector<size_t> heights(bin_count);
if (max_count>MAX_ASTERISK){ if (max_count>MAX_ASTERISK){
for (size_t i = 0; i < bins.size(); i++){ for (size_t i = 0; i < bin_count; i++){
heights[i] = MAX_ASTERISK * (static_cast<double>(bins[i]) /max_count); heights[i] = MAX_ASTERISK * (static_cast<double>(bins[i]) /max_count);
} }
} }
else{ else{
for (size_t i=0; i<bins.size(); i++){ for (size_t i=0; i<bin_count; i++){
heights[i] = bins[i]; heights[i] = bins[i];
} }
} }
for(size_t i=0; i<bins.size(); i++){ for(size_t i=0; i<bin_count; i++){
if (bins[i] < 10){ if (bins[i] < 10){
cout << " " << bins[i] << "|"; cout << " " << bins[i] << "|";
} }
@ -93,12 +88,5 @@ show_histogram_text(vector<size_t> bins){
} }
cout<<"\n"; cout<<"\n";
} }
}
int
main(){
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins);
return 0; return 0;
} }

Загрузка…
Отмена
Сохранить