fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. #define faster() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  5.  
  6. void solve() {
  7. int n;
  8. cin >> n;
  9. int a[n], count0 = 0, count1 = 0, count2 = 0;
  10.  
  11. for (int i = 0; i < n; i++) {
  12. cin >> a[i];
  13. if (a[i] == 0) count0++;
  14. else if (a[i] == 1) count1++;
  15. else count2++;
  16. }
  17.  
  18. for (int i = 0; i < count0; i++) cout << "0 ";
  19. for (int i = 0; i < count1; i++) cout << "1 ";
  20. for (int i = 0; i < count2; i++) cout << "2 ";
  21.  
  22. cout << '\n';
  23. }
  24.  
  25. signed main() {
  26. int test;
  27. cin >> test;
  28. while (test--) {
  29. solve();
  30. }
  31. }
  32.  
Success #stdin #stdout 0.01s 5284KB
stdin
2
5
0 2 1 2 0

3
0 1 0
stdout
0 0 1 2 2 
0 0 1