<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之旅 廣告
                <table id="table1" class="grid grid_tb " border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="grid_left_td" width="10%">描述:?</td><td width="90%"><p>按照指定規則對輸入的字符串進行處理。</p><p>詳細描述:</p><p>將輸入的兩個字符串合并。</p><p>對合并后的字符串進行排序,要求為:下標為奇數的字符和下標為偶數的字符分別從小到大排序。這里的下標意思是字符在字符串中的位置。</p><p>對排訓后的字符串進行操作,如果字符為‘0’——‘9’或者‘A’——‘F’或者‘a’——‘f’,<span style="color:#FF0000">則對他們所代表的16進制的數進行BIT倒序的操作,并轉換為相應的大寫字符</span>。如字符為‘4’,為0100b,則翻轉后為0010b,也就是2。轉換后的字符為‘2’;?如字符為‘7’,為0111b,則翻轉后為1110b,也就是e。轉換后的字符為大寫‘E’。</p><p>?</p><p>舉例:輸入str1為"dec",str2為"fab",合并為“decfab”,分別對“dca”和“efb”進行排序,排序后為“abcedf”,轉換后為“5D37BF”</p><p>接口設計及說明:</p><p>/*</p><p>功能:字符串處理</p><p>輸入:兩個字符串,需要異常處理</p><p>輸出:合并處理后的字符串,具體要求參考文檔</p><p>返回:無</p><p>*/</p><p>void?ProcessString(char*?str1,char?*str2,char?*?strOutput)</p><p>{</p><p>}</p><p>?</p><p>?</p>?</td></tr><tr><td class="grid_left_td">知識點:</td><td>?字符串,排序,位運算?</td></tr><tr><td class="grid_left_td">題目來源:</td><td>?內部整理?</td></tr><tr><td class="grid_left_td">練習階段:</td><td>?中級?</td></tr><tr><td class="grid_left_td">運行時間限制:</td><td>10Sec</td></tr><tr><td class="grid_left_td">內存限制:</td><td>128MByte</td></tr><tr><td class="grid_left_td">輸入:</td><td>?<p>輸入兩個字符串</p>?</td></tr><tr><td class="grid_left_td">輸出:</td><td>?<p>輸出轉化后的結果</p>?</td></tr><tr><td class="grid_left_td">樣例輸入:</td><td><pre>dec fab </pre></td></tr><tr><td class="grid_left_td">樣例輸出:</td><td><pre>5D37BF </pre></td></tr></tbody></table> **關于二進制位的翻轉問題參考:[二進制位的翻轉](http://blog.csdn.net/u013074465/article/details/45485959)** 根據“二進制位翻轉”這篇文章可以得到如下 程序將要使用的、對4位二進制位的翻轉,可以如下處理: ~~~ int main() { unsigned int n; cin >> n; n = n & 0xf; cout << hex << n << endl; n = ((n & 0x5) << 1) | ((n & 0xa) >> 1); n = ((n & 0x3) << 2) | ((n & 0xc) >> 2); cout << n << endl; } ~~~ 上面的程序將形如“1011”的二進制位序列翻轉為“1101”。 解題如下: ~~~ #include <string> //#include <algorithm> #include <iostream> //#include <string.h> //#include <vector> //#include <cmath> #include <sstream> using namespace std; //變形的快排,對字符串分別排序其奇數下標字符、偶數下標字母 int PartQuickSort(string &str, int pos1, int pos2) { char pivot = str[pos1]; int low = pos1, high = pos2; while (high - low > 1) { while (high - low > 1 && str[high] >= pivot) high -= 2; str[low] = str[high]; while (high - low > 1&& str[low] <= pivot) low += 2; str[high] = str[low]; } str[low] = pivot; return low; } void QuickSort(string &str, int pos1, int pos2) { if (pos2 - pos1 > 1) { int part = PartQuickSort(str, pos1, pos2); QuickSort(str, pos1, part - 2); QuickSort(str, part + 2, pos2); } } //按照題目要求對特定字符翻轉其二進制位 void process_str(string &str) { char ch1, ch2 = 0; bool flag = true; int i; for (i = 0; i < str.size(); i++) { flag = true; if (str[i] >= '0' && str[i] <= '9') ch1 = str[i] - '0'; else if (str[i] >= 'a' && str[i] <= 'f') ch1 = str[i] - 'a' + 10; else if (str[i] >= 'A' && str[i] <= 'F') ch1 = str[i] - 'A' + 10; else flag = false; if (flag) { //本題要注意這里將二進制位翻轉的做法。 //例如11的二進制為1011,翻轉后為1101 ch2 = 0; ch2 |= (ch1 & (1 << 0)) << 3; ch2 |= (ch1 & (1 << 1)) << 1; ch2 |= (ch1 & (1 << 2)) >> 1; ch2 |= (ch1 & (1 << 3)) >> 3; if (ch2 < 10) { str[i] = '0' + ch2; //cout << str[i] << endl; } else { str[i] = 'A' + ch2 - 10; //cout << str[i] << endl; } } } } int main() { string str, str1, str2; getline(cin, str); stringstream stream(str); stream >> str1 >> str2; str1 += str2; str2 = str1; //分別對字符串的偶數下標、奇數下標排序 if (str1.size() % 2 != 0) { QuickSort(str1, 0, str1.size() - 1); QuickSort(str1, 1, str1.size() - 2); } else { QuickSort(str1, 0, str1.size() - 2); QuickSort(str1, 1, str1.size() - 1); } process_str(str1); cout << str1 << endl; } ~~~ ![](https://box.kancloud.cn/2016-06-07_575683c129173.jpg)
                  <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>

                              哎呀哎呀视频在线观看