题解 | #字符串合并处理#
字符串合并处理
https://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f
#include <ctype.h> #include <stdio.h> #include <string.h> int main() { char input[] = {"0123456789abcdefABCDEF"}; char output[] = {"084C2A6E195D3B7F5D3B7F"}; char str[200]={0}, str2[100]; scanf("%s %s", str, str2); int n1 = strlen(str); int n2 = strlen(str2); for (int i = n1; i < n1 + n2; i++) { str[i] = str2[i - n1]; } int j; int len = strlen(str); for (int k = 0; k <= 1; k++) { for (int i = k; i < len; i = i + 2) { char target = str[i]; for (j = i - 2; j >= 0; j = j - 2) { if (str[j] > target) { str[j + 2] = str[j]; } else { break; } } str[j+2] = target; } } for(int i = 0;i<len;i++) { if(isdigit(str[i]) || str[i]>='a'&&str[i]<='f' || str[i]>='A'&&str[i]<='F') { for(int j = 0;j<22;j++) { if(str[i] == input[j]) { str[i] = output[j]; break; } } } } printf("%s",str); }