<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之旅 廣告
                # 重新排列二進制字符串作為 x 和 y 的交替出現 > 原文: [https://www.geeksforgeeks.org/rearrange-binary-string-alternate-x-y-occurrences/](https://www.geeksforgeeks.org/rearrange-binary-string-alternate-x-y-occurrences/) 給定一個二進制字符串`s`,并給出兩個整數`x`和`y`。 任務是按照給定的字符串進行排列,以使 0 代表`X`,然后 1 代表`Y`,依此類推,直到完成 0 或 1 之一。 然后將字符串的其余部分連接起來并打印最終的字符串。 給出:`x`或`y`不能為 0 例子: ``` Input : s = "0011" x = 1 y = 1 Output : 0101 x is 1 and y is 1\. So first we print '0' one time the '1' one time and then we print '0', after printing '0', all 0's are vanished from the given string so we concatenate rest of the string which is '1'. Input : s = '1011011' x = 1 y = 1 Output : 0101111 ``` 1. 計算字符串中 0 和 1 的數量。 2. 循環運行,直到兩個字母之一完成。 1. 首先打印 0 直到`x`且遞減計數為 0。 2. 然后打印 1 直到`y`且遞減計數為 0。 ## C++ ```cpp // C++ program to arrange given string #include <bits/stdc++.h> using namespace std; // Function which arrange the given string void arrangeString(string str, int x, int y) { ????int count_0 = 0; ????int count_1 = 0; ????int len = str.length(); ????// Counting number of 0's and 1's in the ????// given string. ????for (int i = 0; i < len; i++) { ????????if (str[i] == '0') ????????????count_0++; ????????else ????????????count_1++; ????} ????// Printing first all 0's x-times ????// and decrement count of 0's x-times ????// and do the similar task with '1' ????while (count_0 > 0 || count_1 > 0) { ?????for (int j = 0; j < x && count_0 > 0; j++) { ????????if (count_0 > 0) { ???????????cout << "0"; ???????????count_0--; ????????} ?????} ?????for (int j = 0; j < y && count_1 > 0; j++) { ????????if (count_1 > 0) { ???????????cout << "1"; ???????????count_1--; ????????} ??????} ????} } // Driver Code int main() { ????string str = "01101101101101101000000"; ????int x = 1; ????int y = 2; ????arrangeString(str, x, y); ????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>

                              哎呀哎呀视频在线观看