Skip to content

Commit 972dfbf

Browse files
authored
Arrays | C++ div-bargali#275
Arrays | C++ div-bargali#275
2 parents 6509fb8 + ab93553 commit 972dfbf

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <iostream>
2+
using namespace std;
3+
#define ll long long int
4+
#define MAXSIZE 100
5+
6+
int main() {
7+
ll arr[MAXSIZE],i=0;
8+
while(cin>>arr[i]){
9+
i++;
10+
}
11+
ll n = i;
12+
13+
ll pos[n],neg[n];
14+
ll i,pi=0,pn=0,xp=0,xn=0;
15+
for(i=0;i<n;i++){
16+
if(arr[i] >= 0){
17+
pos[pi] = arr[i];
18+
pi++;
19+
}
20+
else{
21+
neg[pn] = arr[i];
22+
pn++;
23+
}
24+
}
25+
for(i=0;i<n;i++){
26+
if(i%2==0 && xp<pi){
27+
arr[i] = pos[xp];
28+
xp++;
29+
}
30+
else if(i%2!=0 && xn<pn){
31+
arr[i] = neg[xn];
32+
xn++;
33+
}
34+
else if(xp>=pi){
35+
arr[i] = neg[xn++];
36+
}
37+
else if(xn>=pn){
38+
arr[i] = pos[xp++];
39+
}
40+
}
41+
42+
for(i=0;i<n;i++){
43+
cout<<arr[i]<<" ";
44+
}
45+
return 0;
46+
}

0 commit comments

Comments
 (0)