#include<bits/stdc++.h>
using namespace std;
char change(char c)
{
int flag=0;
if(c<='9'&&c>='0')
{
c=c-'0';
flag=1;
}
else if(c<='f'&&c>='a')
{
c=c-'a'+10;
flag=1;
}
else if(c<='F'&&c>='A')
{
c=c-'A'+10;
flag=1;
}
if(flag==1)
{
int temp=c;
int sum=0,k=8;
while(temp)
{
sum+=(temp%2)*k;
k/=2;
temp/=2;
}
if(sum>=10)c=(sum-10)+'A';
else c=sum+'0';
}
return c;
}
void ProcessString(char* str1,char *str2,char * strOutput)
{
char *u,a1[10000],a2[10000];
u=new char[10000];
sprintf(u,"%s%s",str1,str2);
int num1=0,num2=0;
for(int i=0; u[i]!='\0'; i++)
{
if(i%2==0)
{
a1[num1++]=u[i];
}
else
{
a2[num2++]=u[i];
}
}
sort(a1,a1+num1);
sort(a2,a2+num2);
for(int i=0; i<num1; i++)
a1[i]=change(a1[i]);
for(int i=0; i<num2; i++)
a2[i]=change(a2[i]);
int n=0;
for(n=0; n<num1+num2; n++)
{
if(n%2==0)strOutput[n]=a1[n/2];
else strOutput[n]=a2[n/2];
}
strOutput[n]='\0';
delete u;
}
int main()
{
char *str1,*str2,*strOutput;
str1=new char[10000];
str2=new char[10000];
strOutput=new char[10000];
while(scanf("%s%s",str1,str2)!=EOF)
{
ProcessString(str1,str2,strOutput);
printf("%s\n",strOutput);
}
return 0;
}
字符串合并处理
最新推荐文章于 2022-09-06 16:43:53 发布