#include <cstdio> #include <vector> #include <cstring> #include <iostream> using namespace std; int main() { //freopen("input2(1).txt", "r", stdin); int m, n; int i, j, num = 0; int a[205][205]; memset(a, -1, sizeof(a)); scanf("%d%d", &m, &n); for(i = 0; i < m; i++) for(j = 0; j < n; j++) scanf("%d", &a[i][j]); int tot = 0, x = -1, y = 0; while(tot < m * n) { while(x + 1 < m && a[x + 1][y] != -1) { printf("%d ", a[++x][y]); a[x][y] = -1; ++tot; } while(y + 1 < n && a[x][y + 1] != -1) { printf("%d ", a[x][++y]); a[x][y] = -1; ++tot; } while(x - 1 >= 0 && a[x - 1][y] != -1) { printf("%d ", a[--x][y]); a[x][y] = -1; ++tot; } while(y - 1 >= 0 && a[x][y - 1] != -1) { printf("%d ", a[x][--y]); a[x][y] = -1; ++tot; } } return 0; } /************************************************************** Problem: 1840 User: admin Language: C++ Result: Accepted Time:103 ms Memory:2120 kb ****************************************************************/