<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 創建具有 O 和 X 的交替矩形的矩陣 > 原文: [https://www.geeksforgeeks.org/create-a-matrix-with-alternating-rectangles-of-0-and-x/](https://www.geeksforgeeks.org/create-a-matrix-with-alternating-rectangles-of-0-and-x/) 編寫代碼,輸入兩個數字 m 和 n,并創建一個大小為 mxn(m 行和 n 列)的矩陣,其中每個元素均為 X 或 0。 Xs 和 0s 必須交替填充,矩陣應具有 Xs 的最外面的矩形,然后是 0s 的矩形,然后是 Xs 的矩形,依此類推。 **示例**: ``` Input: m = 3, n = 3 Output: Following matrix X X X X 0 X X X X Input: m = 4, n = 5 Output: Following matrix X X X X X X 0 0 0 X X 0 0 0 X X X X X X Input: m = 5, n = 5 Output: Following matrix X X X X X X 0 0 0 X X 0 X 0 X X 0 0 0 X X X X X X Input: m = 6, n = 7 Output: Following matrix X X X X X X X X 0 0 0 0 0 X X 0 X X X 0 X X 0 X X X 0 X X 0 0 0 0 0 X X X X X X X X ``` ***我們強烈建議最小化瀏覽器,然后自己嘗試。*** 在 Shreepartners Gurgaon 的校園招聘中提出了這個問題。 我遵循以下方法。 **1)**使用[代碼以螺旋形式](https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/)打印矩陣。 **2)**而不是打印數組,而是在數組中插入元素“ X”或“ 0”。 以下是上述方法的實現。 ## C++ ```cpp #include <stdio.h> // Function to print alternating rectangles of 0 and X void fill0X(int m, int n) { ????/*? k - starting row index ????????m - ending row index ????????l - starting column index ????????n - ending column index ????????i - iterator??? */ ????int i, k = 0, l = 0; ????// Store given number of rows and columns for later use ????int r = m, c = n; ????// A 2D array to store the output to be printed ????char a[m][n]; ????char x = 'X'; // Iniitialize the character to be stoed in a[][] ????// Fill characters in a[][] in spiral form. Every iteration fills ????// one rectangle of either Xs or Os ????while (k < m && l < n) ????{ ????????/* Fill the first row from the remaining rows */ ????????for (i = l; i < n; ++i) ????????????a[k][i] = x; ????????k++; ????????/* Fill the last column from the remaining columns */ ????????for (i = k; i < m; ++i) ????????????a[i][n-1] = x; ????????n--; ????????/* Fill the last row from the remaining rows */ ????????if (k < m) ????????{ ????????????for (i = n-1; i >= l; --i) ????????????????a[m-1][i] = x; ????????????m--; ????????} ????????/* Print the first column from the remaining columns */ ????????if (l < n) ????????{ ????????????for (i = m-1; i >= k; --i) ????????????????a[i][l] = x; ????????????l++; ????????} ????????// Flip character for next iteration ????????x = (x == '0')? 'X': '0'; ????} ????// Print the filled matrix ????for (i = 0; i < r; i++) ????{ ????????for (int j = 0; j < c; j++) ????????????printf("%c ", a[i][j]); ????????printf("\n"); ????} } /* Driver program to test above functions */ int main() { ????puts("Output for m = 5, n = 6"); ????fill0X(5, 6); ????puts("\nOutput for m = 4, n = 4"); ????fill0X(4, 4); ????puts("\nOutput for m = 3, n = 4"); ????fill0X(3, 4); ????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>

                              哎呀哎呀视频在线观看