forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path054. Array.cpp
57 lines (55 loc) · 804 Bytes
/
054. Array.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
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
#define lli long long int
#define endl "\n"
using namespace std;
int main()
{
vector <int> vn, vp, v0,vextra;
int n,data,flag = 0;
cin>>n;
for(int i=0; i<n;i++)
{
cin>>data;
if(data == 0)
v0.push_back(data);
else if(data > 0)
vp.push_back(data);
else
{
if(flag == 0)
{
vn.push_back(data);
flag = 1;
}
else
vextra.push_back(data);
}
}
if(vextra.size()%2 == 0)
{
for(auto c: vextra)
vp.push_back(c);
}
else
{
int flag2 = 0;
for(auto c: vextra)
{
if(flag2 == 0){
v0.push_back(c);
flag2 = 1;
}
else
vp.push_back(c);
}
}
cout<<1<<" "<<vn[0]<<endl;
cout<<vp.size()<<" ";
for(auto c: vp)
cout<<c<<" ";
cout<<endl;
cout<<v0.size()<<" ";
for(auto c: v0)
cout<<c<<" ";
return 0;
}