第一题 #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; }
点赞 评论

相关推荐

01-26 18:45
门头沟学院 Java
一天代码十万三:哥们实习再包一下吧,产出太笼统了,尽量体现业务
点赞 评论 收藏
分享
02-08 15:53
门头沟学院 Java
CoderEcho:让公司知道便宜没好货
点赞 评论 收藏
分享
牛客网
牛客企业服务