task15.c 856 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <stdio.h>
  2. #define MAX 100
  3. int main(void)
  4. {
  5. int n, k, nd = 0, x = 0, y = 0, l = 0, m = 0;
  6. int matrix[MAX][MAX];
  7. int dir[2] = {-1, 1};
  8. scanf("%d", &k);
  9. for (int key = 0; key < k; key++) {
  10. scanf("%d", &n);
  11. for (int i = 0; i < n; i++)
  12. for (int j = 0; j < n; j++)
  13. scanf("%d", matrix[i] + j);
  14. x = 0;
  15. y = n - 1;
  16. nd = 2 * y + 1;
  17. for (int i = 0, l = 1, m = 0; i < nd; i++ % 2 == 0 ? m++ : l++) {
  18. while (i % 2 == 0 ? y != 0 : y != n - 1) {
  19. printf("%d ", matrix[y][x]);
  20. y += dir[i % 2];
  21. x += dir[(i + 1) % 2];
  22. }
  23. printf("%d ", matrix[y][x]);
  24. x += dir[(i + 1) % 2] * m;
  25. y += dir[(i + 1) % 2] * l;
  26. }
  27. putchar('\n');
  28. }
  29. return 0;
  30. }