题解 | #字符串合并处理#
字符串合并处理
http://www.nowcoder.com/practice/d3d8e23870584782b3dd48f26cb39c8f
#include <stdio.h>
#include <string.h>
//读取,选择排序
//字典序列
//需要注意题目中用例会出现非A-F字母,原样输出即可
int main()
{
char str1[101];
char str2[101];
char input[] = {"0123456789abcdefABCDEF"};
char output[] = {"084C2A6E195D3B7F5D3B7F"};
while (scanf("%s", str1) != EOF)
{
scanf("%s", str2);
char str[202] = {'\0'};
strcpy(str, str1);
strcat(str, str2);
int len = strlen(str);
char temp;
//按str[i]-'0'排序
for (int i = 0; i < len; i += 2)
{
for (int j = i + 2; j < len; j += 2)
{
if (str[j] - '0' < str[i] - '0')
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
for (int i = 1; i < len; i += 2)
{
for (int j = i + 2; j < len; j += 2)
{
if (str[j] - '0' < str[i] - '0')
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
char outstr[202] = {'\0'};
for (int i = 0; i < len; i++)
{
outstr[i]= str[i];
for (int j = 0; j < 22; j++)
{
if (str[i] == input[j])
outstr[i] = output[j];
}
}
printf("%s\n",outstr);
}
return 0;
}