<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 以防螺旋形式打印矩陣 > 原文: [https://www.geeksforgeeks.org/print-matrix-antispiral-form/](https://www.geeksforgeeks.org/print-matrix-antispiral-form/) 給定 2D 數組,任務是以反螺旋形式打印矩陣: **示例**: [![spiral](https://img.kancloud.cn/ba/f7/baf76a10518813a00b242131fe6d0ad9_256x197.png)](https://media.geeksforgeeks.org/wp-content/uploads/spiral1.jpg) 輸出:16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 ``` Input : arr[][4] = {1, 2, 3, 4 5, 6, 7, 8 9, 10, 11, 12 13, 14, 15, 16}; Output : 10 11 7 6 5 9 13 14 15 16 12 8 4 3 2 1 Input :arr[][6] = {1, 2, 3, 4, 5, 6 7, 8, 9, 10, 11, 12 13, 14, 15, 16, 17, 18}; Output : 11 10 9 8 7 13 14 15 16 17 18 12 6 5 4 3 2 1 ``` 想法很簡單,我們以螺旋形式遍歷矩陣[,并將所有遍歷的元素放入堆棧中。 最后從堆棧中逐一列出并打印它們。](https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/) ## C++ ```cpp // C++ program to print matrix in anti-spiral form #include <bits/stdc++.h> using namespace std; #define R 4 #define C 5 void antiSpiralTraversal(int m, int n, int a[R][C]) { ????int i, k = 0, l = 0; ????/*? k - starting row index ????????m - ending row index ????????l - starting column index ????????n - ending column index ????????i - iterator? */ ????stack<int> stk; ????while (k <= m && l <= n) ????{ ????????/* Print the first row from the remaining rows */ ????????for (i = l; i <= n; ++i) ????????????stk.push(a[k][i]); ????????k++; ????????/* Print the last column from the remaining columns */ ????????for (i = k; i <= m; ++i) ????????????stk.push(a[i][n]); ????????n--; ????????/* Print the last row from the remaining rows */ ????????if ( k <= m) ????????{ ????????????for (i = n; i >= l; --i) ????????????????stk.push(a[m][i]); ????????????m--; ????????} ????????/* Print the first column from the remaining columns */ ????????if (l <= n) ????????{ ????????????for (i = m; i >= k; --i) ????????????????stk.push(a[i][l]); ????????????l++; ????????} ????} ????while (!stk.empty()) ????{ ????????cout << stk.top() << " "; ????????stk.pop(); ????} } /* Driver program to test above functions */ int main() { ????int mat[R][C] = ????{ ????????{1,? 2,? 3,? 4,? 5}, ????????{6,? 7,? 8,? 9,? 10}, ????????{11, 12, 13, 14, 15}, ????????{16, 17, 18, 19, 20} ????}; ????antiSpiralTraversal(R-1, C-1, mat); ????return 0; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看