fork(1) download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int n;
  9. cin >> n;
  10. vector<int> vv;
  11. for (int i = 0; i < n; ++i)
  12. for (int j = 0; j < n; ++j)
  13. {
  14. int v;
  15. scanf("%d", &v);
  16. vv.push_back(v);
  17.  
  18. }
  19.  
  20. sort(vv.begin(), vv.end());
  21. vv.push_back(-1);
  22. vv.push_back(-1);
  23. vv.push_back(-1);
  24. int p = 0;
  25. bool first = true;
  26. int n_printed = 0;
  27. while (vv[p] >= 0)
  28. {
  29. if (vv[p + 1] == vv[p])
  30. {
  31. p += 2;
  32. continue;
  33. }
  34.  
  35.  
  36. if (first)
  37. first = false;
  38. else
  39. cout << " ";
  40. cout << vv[p];
  41. vv[p] = -1;
  42. ++p;
  43.  
  44. ++n_printed;
  45. }
  46.  
  47. if (n_printed < n)
  48. {
  49. for (int i = n * n - 1; i >=0 && n_printed < n; --i)
  50. if (vv[i] >= 0)
  51. {
  52. if (first)
  53. first = false;
  54. else
  55. cout << " ";
  56.  
  57. cout << vv[i];
  58. ++n_printed;
  59. }
  60. }
  61.  
  62. return 0;
  63. }
Success #stdin #stdout 0s 3420KB
stdin
2
1 1 1 1
stdout
1 1