<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之旅 廣告
                # 計算右側較小的元素 > 原文: [https://www.geeksforgeeks.org/count-smaller-elements-on-right-side/](https://www.geeksforgeeks.org/count-smaller-elements-on-right-side/) 在數組中每個元素的右邊編寫一個函數以計算較小元素的數量。 給定一個不同整數的未排序數組`arr[]`,請構造另一個數組`countSmaller[]`,以便`countSmaller[i]`在數組中每個元素`arr[i]`的右側包含較小元素的數量。 例子: ``` Input: arr[] = {12, 1, 2, 3, 0, 11, 4} Output: countSmaller[] = {6, 1, 1, 1, 0, 1, 0} (Corner Cases) Input: arr[] = {5, 4, 3, 2, 1} Output: countSmaller[] = {4, 3, 2, 1, 0} Input: arr[] = {1, 2, 3, 4, 5} Output: countSmaller[] = {0, 0, 0, 0, 0} ``` [](https://practice.geeksforgeeks.org/problem-page.php?pid=585) ## 強烈建議您在繼續解決方案之前,單擊此處進行練習。 **方法 1(簡單)** 使用兩個循環。 外循環從左到右拾取所有元素。 內部循環遍歷選中元素右側的所有元素,并更新`countSmaller[]`。 ## C ``` void constructLowerArray (int *arr[], int *countSmaller, int n) { ??int i, j; ??// initialize all the counts in countSmaller array as 0 ??for? (i = 0; i < n; i++) ?????countSmaller[i] = 0; ??for (i = 0; i < n; i++) ??{ ????for (j = i+1; j < n; j++) ????{ ???????if (arr[j] < arr[i]) ?????????countSmaller[i]++; ????} ??} } /* Utility function that prints out an array on a line */ void printArray(int arr[], int size) { ??int i; ??for (i=0; i < size; i++) ????printf("%d ", arr[i]); ??printf("\n"); } // Driver program to test above functions int main() { ??int arr[] = {12, 10, 5, 4, 2, 20, 6, 1, 0, 2}; ??int n = sizeof(arr)/sizeof(arr[0]); ??int *low = (int *)malloc(sizeof(int)*n); ??constructLowerArray(arr, low, n); ??printArray(low, 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>

                              哎呀哎呀视频在线观看