题解 | #字符串合并处理#
字符串合并处理
https://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f
#include <stdio.h> #include <string.h> #include <stdlib.h> typedef char EType; int cmp(const void *left,const void *right) { return *(EType*)left-*(EType*)right; } int main() { EType str1[201]; EType str2[101]; scanf("%s%s",str1,str2); strcat(str1,str2);//将两个字符串合并 EType js[101]={0}; EType os[101]={0}; int len=strlen(str1); int i,j; EType c; EType sixt[16]={'0','8','4','C','2','A','6','E','1','9','5','D','3','B','7','F'}; for(i=0;i<len-2;i++)//奇偶下标分别排序 { for(j=i+2;j<len;j+=2) { if(str1[i]>str1[j]) { c=str1[i]; str1[i]=str1[j]; str1[j]=c; } } } int shi[len]; for(i=0;i<len;i++)//字符转换为十进制数字 { if(str1[i]>='0'&&str1[i]<='9') { shi[i]=str1[i]-'0'; }else if(str1[i]>='a'&&str1[i]<='f') { shi[i]=str1[i]-'a'+10; }else if(str1[i]>='A'&&str1[i]<='F') { shi[i]=str1[i]-'A'+10; }else{ shi[i]=-1; continue; } } for(i=0;i<len;i++) { if(shi[i]==-1) { continue; }else{ str1[i]=sixt[shi[i]];//十进制转为十六进制 } } printf("%s\n",str1); return 0; }