Advertisement
a53

Fata Morgana

a53
Feb 1st, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(NULL); cout.tie(NULL);
  9. int n;
  10. cin>>n;
  11. unsigned int v[n+1];
  12. v[0]=0;
  13. for(int i=1;i<=n;++i)
  14. cin>>v[i];
  15. sort(v,v+n+1);
  16. int j=1,a[n+1];
  17. for(int i=1;i<=n/2;++i)
  18. a[j++]=v[i],a[j++]=v[n/2+i];
  19. if(n%4!=0)
  20. swap(a[n-1],a[n]);
  21. bool ok=false;
  22. for(int i=1;i<=n;i+=2)
  23. if(a[i]==a[i+1])
  24. ok=true,i=n+1;
  25. if(ok)
  26. for(int i=1;i<=n;++i)
  27. cout<<v[i]<<' ';
  28. else
  29. for(int i=1;i<=n;++i)
  30. cout<<a[i]<<' ';
  31. return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement