fork(1) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <algorithm>
  12. #include <iomanip>
  13. #define dibs reserve
  14. #define OVER9000 1234567890
  15. #define patkan 9
  16. #define tisic 47
  17. #define soclose 10e-7
  18. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  19. #define chocolate win
  20. #define ff first
  21. #define ss second
  22. #define abs(x) ((x < 0)?-(x):(x))
  23. // mylittlepony
  24. using namespace std;
  25.  
  26. int main() {
  27. // freopen("cubes.in","r",stdin);
  28. int T;
  29. scanf(" %d",&T);
  30. for(int t =0; t < T; t++) {
  31. int N;
  32. scanf(" %d",&N);
  33. printf("Case %d:\n",t+1);
  34. vector<int> A(N);
  35. for(int i =0; i < N; i++) scanf(" %d",&A[i]);
  36. sort(A.begin(),A.end());
  37. vector<int> B(N);
  38. int a =0, b =N-1;
  39. for(int i =N-1; i > 0; i -=2) {
  40. B[b] =A[i];
  41. B[a] =A[i-1];
  42. b--, a++;}
  43. if(N%2 != 0) B[a] =A[0];
  44. for(int i =0; i < N; i++) {
  45. if(i > 0) printf(" ");
  46. printf("%d",B[i]);}
  47. printf("\n");}
  48. return 0;}
  49.  
  50. // look at my code
  51. // my code is amazing
Success #stdin #stdout 0s 3436KB
stdin
2
3
1 2 3
5
4 5 2 1 3
stdout
Case 1:
2 1 3
Case 2:
4 2 1 3 5