<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 給定 1、2、3……k 以之字形打印它們。 > 原文: [https://www.geeksforgeeks.org/given-1s-2s-3s-ks-print-zig-zag-way/](https://www.geeksforgeeks.org/given-1s-2s-3s-ks-print-zig-zag-way/) 給定的行數和列數。 并給定需要打印的數字 1、2、3…k。 以之字形打印它們。 確保 n * m = 1 的個數+ 2 的個數+ 3 的+…+ k 的個數 例子: ``` Input : 2 3 2 1 2 1 Output : 1 1 2 4 3 3 Explanation : Here number of rows are 2 and number of columns are 3 and number of 1's are 2 number of 2's are 1 number of 3's are 2 number of 4's are 1 ----------- | 1 | 1 | 2 | | 3 | 3 | 4 | ----------- Input : 4 3 2 4 3 1 2 Output : 1 1 2 2 2 2 3 3 3 5 5 4 Explanation : Here number of rows are 4 and number of columns are 3 and number of 1's are 2 number of 2's are 4 [Note that 2s are printed in] number of 3's are 3 [zig zag manner] number of 4's are 1 number of 5's are 2 ``` **方法**:我們制作了一個二維數組,以之字形方式存儲所有元素。 我們將遍歷數字數組的所有元素,并將第 i 個索引的數組的所有數字插入二維數組,直到其變為零。 ## C++ ```cpp // CPP program to print? given number of 1's,? // 2's, 3's ....k's in? zig-zag way. #include <bits/stdc++.h> using namespace std; // function that prints? given number of 1's,? // 2's, 3's ....k's in zig-zag way. void ZigZag(int rows, int columns, int numbers[]) { ????int k = 0; ????// two-dimensional array to store numbers.? ????int arr[rows][columns]; ????for (int i=0; i<rows; i++) ????{ ????????// for even row. ????????if (i%2==0) ????????{ ????????????// for each column. ????????????for (int j=0; j<columns and? ????????????????????numbers[k]>0; j++) ????????????{ ????????????????// storing element. ????????????????arr[i][j] = k+1; ????????????????// decrement element at? ????????????????// kth index.? ????????????????numbers[k]--; ????????????????// if array contains zero ????????????????// then increment index to? ????????????????// make this next index ????????????????if (numbers[k] == 0) ????????????????????k++; ????????????} ????????} ????????// for odd row. ????????else ????????{ ????????????// for each column. ????????????for (int j=columns-1; j>=0 and? ????????????????numbers[k]>0; j--) ????????????{ ????????????????// storing element. ????????????????arr[i][j] = k+1; ????????????????// decrement element? ????????????????// at kth index. ????????????????numbers[k]--; ????????????????// if array contains zero then? ????????????????// increment index to make this? ????????????????// next index. ????????????????if (numbers[k]==0) ????????????????????k++; ????????????} ????????} ????} ????// printing the stored elements. ????for (int i=0;i<rows;i++) ????{ ????????for (int j=0;j<columns;j++) ????????????cout << arr[i][j] << " "; ????????cout << endl; ????} } // Driver code for above function. int main() { ????int rows = 4; ????int columns = 5; ????int Numbers[] = {3, 4, 2, 2, 3, 1, 5}; ????ZigZag(rows, columns, Numbers);???? ????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>

                              哎呀哎呀视频在线观看