-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSort in specific order.cpp
46 lines (41 loc) · 1016 Bytes
/
Sort in specific order.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Problem Statement : https://practice.geeksforgeeks.org/problems/sort-in-specific-order/0/?track=SP-Arrays%20and%20Searching
Asked in : Microsoft
Code By:
Abhinav,
CSE, NIT P
(Masters_Abh on codechef, codeforces, hackerrank and Spoj)
*/
#include <bits/stdc++.h>
using namespace std;
#define lint long long int
int main() {
lint t;
cin>>t;
while(t--){
lint n;
cin>>n;
lint a[n];
multiset<lint, greater<lint> > odd; // For descending order of odd numbers.
multiset<lint> even; // Ascending order of even numbers.
for(lint i=0;i<n;i++){
cin>>a[i];
if(a[i]%2==0){
even.insert(a[i]);
}
else{
odd.insert(a[i]);
}
}
multiset<lint, greater<lint> > :: iterator od;
multiset<lint> :: iterator ev;
for(od = odd.begin();od!=odd.end();++od){
cout<<*od<<" ";
}
for(ev = even.begin();ev!=even.end();++ev){
cout<<*ev<<" ";
}
cout<<endl;
}
return 0;
}