forked from t3nsor/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 2
/
arrange.cpp
36 lines (36 loc) · 648 Bytes
/
arrange.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
// 2008-05-09
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int T;
cin >> T;
int i;
int amplifier[100000];
int a[100000];
for (i=0; i<T; i++)
{
int Ni,j,ones=0;
cin >> Ni;
for (j=0; j<Ni; j++)
{
int n;
cin >> n;
if (n==1) ones++; else amplifier[j-ones]=n;
}
Ni-=ones;
sort(amplifier,amplifier+Ni);
if (Ni==2 && amplifier[0]==2 && amplifier[1]==3);
else
reverse(amplifier,amplifier+Ni);
for (j=0; j<ones; j++)
a[j]=1;
for (j=ones; j<Ni+ones; j++)
a[j]=amplifier[j-ones];
for (j=0; j<Ni+ones-1; j++)
cout << a[j] << ' ';
cout << a[Ni+ones-1] << endl;
}
return 0;
}