fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. int ile1st(int tab[], int n)
  7. {
  8. int ile=1;
  9. while(tab[n-1]==tab[n-2])
  10. {
  11. ++ile;
  12. --n;
  13. }
  14. return ile;
  15. }
  16.  
  17. void wypisz(int tab[], int n, int ile)
  18. {
  19. for(int i=0; i<ile; ++i)
  20. {
  21. cout<<tab[n-i-1]<<" ";
  22. }
  23. for(int i=0; i<n-ile; i++)
  24. {
  25. cout<<tab[i]<<" ";
  26. }
  27. cout<<endl;
  28.  
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34. int d,n;
  35. cin>>d;
  36. while(d--)
  37. {
  38. cin>>n;
  39. int* tab=new int [n];
  40. for(int i=0; i<n; i++)
  41. {
  42. cin>>tab[i];
  43. }
  44. sort(tab,tab+n);
  45. wypisz(tab, n, ile1st(tab,n));
  46.  
  47. delete [] tab;
  48. }
  49. }
  50.  
Success #stdin #stdout 0s 3468KB
stdin
3
5
1 2 3 4 5
5
4 5 2 3 5
2
1 1
stdout
5 1 2 3 4 
5 5 2 3 4 
1 1