fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  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-1; i++)
  24. {
  25. cout<<tab[i]<<" ";
  26. }
  27.  
  28. }
  29.  
  30.  
  31. int main()
  32. {
  33. int d,n;
  34. cin>>d;
  35. while(d)
  36. {
  37. cin>>n;
  38. int* tab=new int [n];
  39. for(int i=0; i<n; i++)
  40. {
  41. cin>>tab[i];
  42. }
  43. sort(tab,tab+8);
  44.  
  45. wypisz(tab, n, ile1st(tab,n));
  46.  
  47. delete [] tab;
  48. --d;
  49. }
  50. }
  51.  
Runtime error #stdin #stdout #stderr 0s 3424KB
stdin
1
5
1 2 3 5 5
stdout
3 0 0 1 
stderr
*** Error in `./prog': free(): invalid next size (fast): 0x09156a10 ***