-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrange_1.c
51 lines (43 loc) · 903 Bytes
/
arrange_1.c
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
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
int amplifier[1111111],amplifiers;
int compare_ints(const void *ptr1,const void *ptr2) {
return *((int*)ptr1)-*((int*)ptr2);
}
int main()
{
int cases;
int numbers,number;
int ones,twos,threes;
int reverse23;
scanf("%d",&cases);
while(cases--) {
scanf("%d",&numbers);
ones=twos=threes=0;
amplifiers=0;
while(numbers--) {
scanf("%d",&number);
switch(number) {
case 1:ones++;break;
case 2:assert(!twos);twos++;break;
case 3:assert(!threes);threes++;break;
defalult:amplifier[amplifiers++]=number;break;
}
}
qsort(amplifier,amplifiers,sizeof(int),compare_ints);
reverse23=!amplifiers;
while(ones--) printf("1 ");
while(amplifiers) printf("%d ",amplifier[--amplifiers]);
if(reverse23) {
if(twos) printf("2 ");
if(threes) printf("3 ");
}
else {
if(threes) printf("3 ");
if(twos) printf("2 ");
}
printf("\n");
}
return 0;
}