• Написать программу:
    Упорядочьте элементы строк массива по убыванию модулей элементов методом двоичного включения (pascal)

Ответы 1

  • #include <iostream>

    #include <algorithm>

    #include <vector>

    #include <random>

     

    int main()

    {

     srand(time(NULL));

     const int n = 20;

     std::vector<int> arr(n);

     for(int i = 0;i < n;i++)

     {

         arr[i] = -20 + rand() % 40;

     }

     

     for(const int i : arr)

     {

         std::cout << i << " ";

     }

     std::cout << std::endl;

     

     std::sort(arr.begin(),arr.end(),[](int a,int b){ return abs(a) > abs(b); });

     for(const int i : arr)

     {

         std::cout << i << " ";

     }

     

    }

  • Добавить свой ответ

Еще вопросы

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years