image.png

    1. #include <iostream>
    2. #include <vector>
    3. #include <string>
    4. #include <algorithm>
    5. using namespace std;
    6. string code_book = "0123456789ABCDEFabcdef";
    7. string decode_book = "084C2A6E195D3B7F5D3B7F";
    8. string code(string input) {
    9. string output;
    10. output = input;
    11. for (int i = 0; i < input.size(); i++)
    12. {
    13. for (int j = 0; j < code_book.size(); j++)
    14. {
    15. if (output[i]==code_book[j])
    16. {
    17. output[i] = decode_book[j];
    18. //*****************************************
    19. //必须写break,否则会被重复处理
    20. //*****************************************
    21. break;
    22. }
    23. }
    24. }
    25. return output;
    26. }
    27. int main() {
    28. string str_1;
    29. string str_2;
    30. while (cin>>str_1)
    31. {
    32. cin >> str_2;
    33. string str_all = str_1 + str_2;
    34. str_1.clear();
    35. str_2.clear();
    36. for (int i = 0; i < str_all.size(); i++)
    37. {
    38. if (i%2==0)
    39. {
    40. str_1+=str_all[i];
    41. }
    42. else
    43. {
    44. str_2 += str_all[i];
    45. }
    46. }
    47. sort(str_1.begin(), str_1.end());
    48. sort(str_2.begin(), str_2.end());
    49. int str_1_index = 0;
    50. int str_2_index = 0;
    51. for (int i = 0; i < str_all.size(); i++)
    52. {
    53. if (i % 2 == 0)
    54. {
    55. str_all[i] = str_1[str_1_index];
    56. str_1_index++;
    57. }
    58. else
    59. {
    60. str_all[i] = str_2[str_2_index];
    61. str_2_index++;
    62. }
    63. }
    64. str_all = code(str_all);
    65. cout << str_all << endl;
    66. }
    67. }