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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 找到四個總和為給定值的元素| 集合 1(n ^ 3 解) > 原文: [https://www.geeksforgeeks.org/find-four-numbers-with-sum-equal-to-given-sum/](https://www.geeksforgeeks.org/find-four-numbers-with-sum-equal-to-given-sum/) 給定一個整數數組,請找到該數組中四個和的總和等于給定值 X 的所有組合。 例如,如果給定的數組為{10,2,3,4,5, 9、7、8}且 X = 23,則您的函數應打印“ 3 5 7 8”(3 + 5 + 7 + 8 = 23)。 **樸素的解決方案**將生成所有可能的四元組,并將每個四元組的和與 X 進行比較。以下代碼使用四個嵌套循環 實現了此簡單方法 ## C++ ```cpp // C++ program for naive solution to // print all combination of 4 elements // in A[] with sum equal to X? #include <bits/stdc++.h> using namespace std; /* A naive solution to print all combination? of 4 elements in A[]with sum equal to X */ void findFourElements(int A[], int n, int X) { // Fix the first element and find other three for (int i = 0; i < n - 3; i++) { ????// Fix the second element and find other two ????for (int j = i + 1; j < n - 2; j++) ????{ ????????// Fix the third element and find the fourth ????????for (int k = j + 1; k < n - 1; k++) ????????{ ????????????// find the fourth ????????????for (int l = k + 1; l < n; l++) ????????????if (A[i] + A[j] + A[k] + A[l] == X) ????????????????cout << A[i] <<", " << A[j]? ?????????????????????<< ", " << A[k] << ", " << A[l]; ????????}? ????} } } // Driver Code int main() { ????int A[] = {10, 20, 30, 40, 1, 2}; ????int n = sizeof(A) / sizeof(A[0]); ????int X = 91; ????findFourElements (A, n, X); ????return 0; } // This code is contributed // by Akanksha Rai ```
                  <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>

                              哎呀哎呀视频在线观看