fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int n, temp[2], nums[100 + 10];
  7. cin >> n;
  8. for (int i = 0; i < n * n; i++)
  9. cin >> nums[i];
  10.  
  11. temp[0] = temp[1] = 0;
  12. for (int i = 0, cnt = 0; i < n; i++, cnt += 5) {
  13. temp[1] = temp[0];
  14. for (int j = 0; j <= i; j++) {
  15. cout << nums[temp[1]] << " ";
  16. temp[1] -= n - 1;
  17. }
  18. temp[0] += n;
  19. }
  20.  
  21. temp[0] -= n - 1;
  22. for (int i = n - 2, cnt = temp[0]; i >= 0; i--, cnt -= 5) {
  23. temp[1] = temp[0];
  24. for (int j = 0; j <= i; j++) {
  25. cout << nums[temp[1]] << " ";
  26. temp[1] -= n - 1;
  27. }
  28. temp[0] += 1;
  29. }
  30.  
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 3300KB
stdin
2
1 2 3 4
stdout
1 3 2 4