Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <algorithm>
- #include <functional>
- using namespace std;
- const int n = 100;
- int main() {
- double arr1[n];
- int arr2[n];
- double a, b;
- std::random_device r;
- std::default_random_engine generator(r());
- cin >> a >> b;
- std::uniform_real_distribution<double> distribution1(a, b);
- auto dice_roll_1 = std::bind(distribution1, generator);
- std::uniform_int_distribution<int> distribution2(trunc(a), trunc(b));
- auto dice_roll_2 = std::bind(distribution2, generator);
- std::generate_n(std::begin(arr1), n, dice_roll_1);
- std::generate_n(std::begin(arr2), n, dice_roll_2);
- std::for_each(std::begin(arr1), std::end(arr1), [](double a) {cout << a << " ";});
- cout << endl;
- std::for_each(std::begin(arr2), std::end(arr2), [](int a) {cout << a << " ";});
- cout << endl;
- double neg_sum = std::accumulate(std::begin(arr1), std::end(arr1), 0, [](double a, double b) { return b < 0 ? a + b : a; });
- int pos_sum = std::accumulate(std::begin(arr2), std::end(arr2), 0, [](int a, int b) { return b > 0 ? a + b : a; });
- double min1, max1;
- auto res1 = std::minmax_element(std::begin(arr1), std::end(arr1));
- min1 = *res1.first;
- max1 = *res1.second;
- int min2, max2;
- auto res2 = std::minmax_element(std::begin(arr2), std::end(arr2), [](int a, int b) { return std::abs(a) < std::abs(b);});
- min2 = *res2.first;
- max2 = *res2.second;
- bool flag1 = false;
- double prod1 = 1.0;
- for(auto x : arr1){
- if(x == min1 || x == max1){
- flag1 = !flag1;
- continue;
- }
- if(flag1){
- prod1 *= x;
- }
- }
- bool flag2 = false;
- double prod2 = 1.0;
- for(auto x : arr2){
- if(x == min2 || x == max2){
- flag2 = !flag2;
- continue;
- }
- if(flag2){
- prod2 *= x;
- }
- }
- cout << neg_sum << " " << pos_sum << " " << prod1 << " " << prod2;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement