#include #include void str_bin(char str1[], char str2[]) { int len1 = strlen(str1); int len2 = strlen(str2); int len = len1 + len2; char temp[len + 1]; // 临时数组保存合并后的字符串 int i = 0, j = 0, k = 0; while (i < len1 && j < len2) { // 合并有序字符串 if (str1[i] <= str2[j]) { temp[k++] = str1[i++]; } else { temp[k++] = str2[j++]; } } while (i < len1) { // 处理剩余字符 temp[k++] = str1[i++]; } while (j < len2) { // 处理剩余字符 temp[k++] = str2[j++]; } temp[k] = '\0'; // 添加字符串结束标志 strcpy(str1, temp); // 将合并后的字符串复制回str1 } int main() { char str1[200]; // 输入字符串最大为100,合并后最大为200 char str2[100]; scanf("%s %s", str1, str2); str_bin(str1, str2); printf("%s\n", str1); return 0; }