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

..

Ничего общего в коммитах. '2f88a51b2ed19f26f7749c168c8ff3abb375a7dd' и '42f18f115a11502d02d2333450c006155b7adf26' имеют совершенно разные истории.

Разница между файлами не показана из-за своего большого размера Загрузить разницу

@ -2,58 +2,50 @@
#include <vector> #include <vector>
using namespace std; using namespace std;
const size_t SCREEN_WIDTH = 80; int main()
const size_t MAX_ASTERISK = SCREEN_WIDTH - 6 - 1; {
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 6 - 1;
size_t bin_count, counts;
cerr << "Enter counts:";
cin >> counts;
struct Input { vector <double> numbers(counts);
vector<double> numbers;
size_t bin_count{};
};
Input for (size_t i = 0; i < counts; i++){
input_data(){ cerr << "Enter array "<< i <<" number:";
size_t number_count; cin >> numbers[i];
cin >> number_count;
Input in;
in.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++){
cin >> in.numbers[i];
} }
cin >> in.bin_count; cerr << "Enter bin_count:";
cin >> bin_count;
return in; double minN = numbers[0], maxN = numbers[0];
}
void
find_minmax(const vector<double>& numbers, double& min, double& max){
min = numbers[0];
max = numbers[0];
for (double x: numbers){ for (double x: numbers){
if (min > x){ if (minN > x){
min = x; minN = x;
} }
if (max < x){ if (maxN < x){
max = x; maxN = x;
} }
} }
}
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count){ double diff = (maxN - minN) / bin_count;
double min, max;
vector <size_t> bins(bin_count); vector <size_t> bins(bin_count);
find_minmax(numbers, min, max);
double diff = (max - min) / bin_count;
size_t max_count = 0; size_t max_count = 0;
for (double x: numbers){ for (size_t i = 0; i < counts; 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 * diff; auto lo = minN + j * diff;
auto hi = min + (j + 1) * diff; auto hi = minN + (j + 1) * diff;
if ((lo <= x) && (hi > x)){ if ((lo <= numbers[i]) && (hi > numbers[i])){
bins[j]++; bins[j]++;
if (bins[j] > max_count){
max_count = bins[j];
}
found = true; found = true;
} }
} }
@ -64,33 +56,41 @@ vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count){
} }
} }
} }
return bins;
}
void show_histogram_text(const vector<size_t>& bins){ bool scaling = false;
for (double x: bins){
if (max_count > MAX_ASTERISK){
scaling = true;
}
for (size_t i = 0; i < bin_count; i++){
cout << " "; cout << " ";
if (x < 100){ if (bins[i] < 100){
cout << " "; cout << " ";
} }
if (x < 10){ if (bins[i] < 10){
cout << " "; cout << " ";
} }
cout << x << "|"; cout << bins[i] << "|";
size_t number_of_stars = x; size_t number_of_stars = bins[i];
if (scaling){
if (bins[i] == max_count){
number_of_stars = MAX_ASTERISK * 1.0;
}
else {
number_of_stars = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
}
}
for (size_t j = 0; j < number_of_stars; j++){ for (size_t j = 0; j < number_of_stars; j++){
cout << "*"; cout << "*";
} }
cout << endl; cout << endl;
}
} if (i < bin_count - 1){
cout << minN + (i + 1) * diff << endl;
}
int main(){ }
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins);
} }

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