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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 按原始順序打印給定數組中的 n 個最小元素 > 原文: [https://www.geeksforgeeks.org/find-n-smallest-element-given-array-order-array/](https://www.geeksforgeeks.org/find-n-smallest-element-given-array-order-array/) 我們給定了一個由 m 個元素組成的數組,我們需要從該數組中找到 n 個最小的元素,但它們的順序必須與給定數組中的元素相同。 **示例**: ``` Input : arr[] = {4, 2, 6, 1, 5}, n = 3 Output : 4 2 1 Explanation : 1, 2 and 4 are 3 smallest numbers and 4 2 1 is their order in given array. Input : arr[] = {4, 12, 16, 21, 25}, n = 3 Output : 4 12 16 Explanation : 4, 12 and 16 are 3 smallest numbers and 4 12 16 is their order in given array. ``` 制作原始數組的副本,然后對副本數組進行排序。 對副本數組排序后,保存所有 n 個最小的數字。 此外,對于原始數組中的每個元素,檢查它是否存在于 n 個最小的數字中,如果它存在于 n 個最小的數組中,則將其打印出來,否則向前移動。 * 制作 copy_arr []* 排序(copy_arr)* 對于 arr []中的所有元素- * 在 copy_arr 的 n 個最小元素中找到 arr [i] * 如果找到,則打印元素 下面是上述方法的實現: ## C++ ```cpp // CPP for printing smallest n number in order #include <bits/stdc++.h> using namespace std; // Function to print smallest n numbers void printSmall(int arr[], int asize, int n) { ????// Make copy of array ????vector<int> copy_arr(arr, arr + asize); ????// Sort copy array ????sort(copy_arr.begin(), copy_arr.begin() + asize); ????// For each arr[i] find whether ????// it is a part of n-smallest ????// with binary search ????for (int i = 0; i < asize; ++i) ????????if (binary_search(copy_arr.begin(),? ????????????????copy_arr.begin() + n, arr[i])) ????????????cout << arr[i] << " "; } // Driver program int main() { ????int arr[] = { 1, 5, 8, 9, 6, 7, 3, 4, 2, 0 }; ????int asize = sizeof(arr) / sizeof(arr[0]);???? ????int n = 5; ????printSmall(arr, asize, n); ????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>

                              哎呀哎呀视频在线观看