按照指定規則對輸入的字符串進行處理。ios
詳細描述:spa
將輸入的兩個字符串合併。設計
對合並後的字符串進行排序,要求爲:下標爲奇數的字符和下標爲偶數的字符分別從小到大排序。這裏的下標意思是字符在字符串中的位置。code
對排序後的字符串進行操做,若是字符爲‘0’——‘9’或者‘A’——‘F’或者‘a’——‘f’,則對他們所表明的16進制的數進行BIT倒序的操做,並轉換爲相應的大寫字符。如字符爲‘4’,爲0100b,則翻轉後爲0010b,也就是2。轉換後的字符爲‘2’; 如字符爲‘7’,爲0111b,則翻轉後爲1110b,也就是e。轉換後的字符爲大寫‘E’。blog
舉例:輸入str1爲"dec",str2爲"fab",合併爲「decfab」,分別對「dca」和「efb」進行排序,排序後爲「abcedf」,轉換後爲「5D37BF」排序
接口設計及說明:接口
/*ci
功能:字符串處理文檔
輸入:兩個字符串,須要異常處理字符串
輸出:合併處理後的字符串,具體要求參考文檔
返回:無
*/
void ProcessString(char* str1,char *str2,char * strOutput)
{
}
1 #include <iostream> 2 #include <algorithm> 3 #include <string> 4 #include <map> 5 using namespace std; 6 7 int main() 8 { 9 map<char, char> m = { 10 {'0', '0'}, {'1', '8'}, {'2', '4'}, {'3', 'C'}, 11 {'4', '2'}, {'5', 'A'}, {'6', '6'}, {'7', 'E'}, 12 {'8', '1'}, {'9', '9'}, {'a', '5'}, {'b', 'D'}, 13 {'c', '3'}, {'d', 'B'}, {'e', '7'}, {'f', 'F'}, 14 {'A', '5'}, {'B', 'D'}, {'C', '3'}, {'D', 'B'}, {'E', '7'}, {'F', 'F'} 15 }; 16 string str1, str2; 17 while(cin >> str1 >> str2) { 18 string str = str1 + str2; 19 str1.clear(); 20 str2.clear(); 21 for(int i = 0; i < str.size(); ++i) { 22 if(i % 2) str2 += str[i]; 23 else str1 += str[i]; 24 } 25 sort(str1.begin(), str1.end()); 26 sort(str2.begin(), str2.end()); 27 //cout << str1 << " " << str2 << endl; 28 for(int i = 0, j = 0, k = 0; i < str.size(); ++i) { 29 if(i % 2) str[i] = str2[k++]; 30 else str[i] = str1[j++]; 31 } 32 //cout << str << endl; 33 for(int i = 0; i < str.size(); ++i) { 34 if(m.count(str[i]) == 0) cout << str[i]; 35 else cout << m[str[i]]; 36 } 37 cout << endl; 38 } 39 }