1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Harlamova29_29 [7]
3 years ago
15

Cerinţa Se dau două numere naturale nenule n și p. Afișați în ordine crescătoare puterile lui n mai mici sau egale cu p. Date de

intrare Programul citește de la tastatură numerele n și p. Date de ieşire Programul afișează pe ecran, în ordine crescătoare, puterile lui n mai mici sau egale cu p, separate prin câte un spațiu. Restricţii şi precizări 2 ≤ n ≤ 10 1 ≤ p < 1.000.000.000
Computers and Technology
1 answer:
rjkz [21]3 years ago
8 0

Given an array of integers (both odd and even), sort them in such a way that the first part of the array contains odd numbers sorted in descending order, rest portion contains even numbers sorted in ascending order.

Explanation:

  • Partition the input array such that all odd elements are moved to left and all even elements on right. This step takes O(n).
  • Once the array is partitioned, sort left and right parts individually. This step takes O(n Log n).

#include <bits/stdc++.h>  

using namespace std;  

void twoWaySort(int arr[], int n)  

{

   int l = 0, r = n - 1;  

   int k = 0;  

   while (l < r) {  

       while (arr[l] % 2 != 0) {  

           l++;  

           k++;  

       }

       while (arr[r] % 2 == 0 && l < r)  

           r--;  

       if (l < r)  

           swap(arr[l], arr[r]);  

   }  

   sort(arr, arr + k, greater<int>());  

   sort(arr + k, arr + n);  

}

int main()  

{  

   int arr[] = { 1, 3, 2, 7, 5, 4 };  

   int n = sizeof(arr) / sizeof(int);  

   twoWaySort(arr, n);  

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

       cout << arr[i] << " ";  

   return 0;  

}

You might be interested in
Jim is a forensic specialist. He seized a suspect computer from a crime scene, removed the hard drive and bagged it, documented
Andreyy89

Answer: Jim left the computer unattended while shopping for supplies to be used at the next crime scene.

Explanation: While transporting the evidence to a secure location (lab), he left the computer unattended in his car and goes shopping for supplies that will be used in his next crime scenes. This act will give the criminals or their accomplice the opportunity to break into his car and tamper with what ever evidence he might have left behind in his car.

7 0
3 years ago
How can i fix this, if i log in my acc it keeps saying wrong nickname or pass. even though my email and pass is correct
Oksanka [162]

Answer:

미안해요. 나는 우리가 단지 부동일 중 하나를 모르지만 그것을 해결하는 방법을 모른다!.

8 0
2 years ago
In your own words, explain the FNAF timeline
tatiyna

Answer:

see shawty problem is, I havent had that phase yet, my cousin would be able to answer this tho

3 0
3 years ago
is skill in using productivity software, such as word processors, spreadsheets, database management systems, and presentation so
Digiron [165]

Answer:

It is general knowledge

Explanation:

What you covered is general knowledge and the entrance to computer science.

4 0
3 years ago
I need help ASAP please and thank you!
hram777 [196]

Answer:

B) Sees failure as a way to get better.

Explanation:

Someone with a growth mindset sees failure as a way to get better. A growth mindset is one that typically do not see failure as a stunning block but rather as a way to get better and excel.

7 0
2 years ago
Other questions:
  • A network administrator is using packet tracer to mock up a network that includes iot devices. What can the administrator do fro
    15·1 answer
  • If you delete a file from removable media, it is stored in the recycle bin where you can recover it until you empty the recycle
    13·1 answer
  • High productivity will typically get you positive attention and feedback when you are on a job.
    7·1 answer
  • Who was the 1st person to use the term television
    11·1 answer
  • Given that the variables x and y have already been declared and assigned values, write an expression that evaluates to true if x
    15·1 answer
  • What is meant by polling mode in communication between software andUART and what is its disadvantage as compared to interrupt mo
    14·1 answer
  • Regarding the Internet of Things (IoT), a business involved in utilities, critical infrastructure, or environmental services can
    14·1 answer
  • HELP ASAP !!! What should be a one-page document?
    7·1 answer
  • Question 6 Which of the following statements about datasets used in Machine Learning is NOT true? 1 point Testing data is data t
    8·1 answer
  • he primary purpose of a database query is to a. find and retrieve specific information. b. correct information in the database.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!