第一题
#include <iostream>
using namespace std;
const int MAXN = 1010;
int A[MAXN][MAXN];

/*
3 3
1 2 3
4 5 6
7 8 9
*/
int main () {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < N; ++i)
        for (int j = 0; j < M; ++j)
            cin >> A[i][j];
    int sr = 0, sc = 0;
    int tr = N - 1, tc = M - 1;
    int cnt = 0;
    while (cnt < M * N) {
        // cout << sr << ", " << sc << endl;
        // cout << tr << ", " << tc << endl;

        for (int r = sr; r <= tr; ++r) {
            cout << A[r][sc] << " ";
            cnt++;
        }
        for (int c = sc + 1; c <= tc; ++c) {
            cout << A[tr][c] << " ";
            cnt++;
        }
        if (sr < tr && sc < tc) {
            for (int r = tr - 1; r >= sr; --r) {
                cout << A[r][tc] << " ";
                cnt++;
            }
            for (int c = tc - 1; c > sc; --c) {
                cout << A[sr][c] << " ";
                cnt++;
            }
        }
        sr++, sc++;
        tr--, tc--;
    }
    return 0;
}