| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

```#include <stdio.h>
#include <string.h>
#include <math.h>
void sort(char *s);     //ASCII码升序排列
void merge(char *s1,char *s2,char *s);      //合并字符串s1，s2到s中，相同字符只保留一个，并按ASCII码升序排列
int main()
{
char s1[10]={"ajerucxbny"};
char s2[10]={"cbdhsykenf"};
char s[20]={};
merge(s1,s2,s);
return 0;
}
void sort(char *s)
{
int len;
len=strlen(s);
int i,j;
for (i = 0; i < len; i++)
{
for (j = i+1; j < len; j++)
{
if(s[i]>s[j])
{
char c;
c=s[i];
s[i]=s[j];
s[j]=c;
}
}
}
}
void merge(char *s1,char *s2,char *s)
{
strcpy(s,s1);
strcat(s,s2);
sort(s);
for (int i = 0; i < 20; i++)
{
for (int i = 0; i < 20; i++)
{
if (s[i]==s[i+1])
{
s[i+1]==s[i+2];
}
}
}
puts(s);
}```

for (int i = 0; i < 20; i++)
{
for (int i = 0; i < 20; i++)

```#include <stdio.h>
#include <limits.h>

void merge( const char* restrict s1, const char* restrict s2, char* restrict s )
{
size_t counts[1+CHAR_MAX-CHAR_MIN] = { 0 };
for( const char* p=s1; *p; ++p )
++counts[*p-CHAR_MIN];
for( const char* p=s2; *p; ++p )
++counts[*p-CHAR_MIN];

for( size_t i=0; i!=sizeof(counts)/sizeof(counts[0]); ++i )
if( counts[i] != 0 )
*s++ = i+CHAR_MIN;
*s = '\0';
}

int main( void )
{
char s[100];
merge( "ccbbaa", "ddccbb", s );
puts( s );
}```

char s1[10]={"ajerucxbny"};
char s2[10]={"cbdhsykenf"};

strcpy(s,s1);
strcat(s,s2);

https://zh.

```#include <stdio.h>
#include <string.h>
#include <math.h>
void sort(char *s);     //ASCII码升序排列
void merge(char *s1,char *s2,char *s);      //合并字符串s1，s2到s中，相同字符只保留一个，并按ASCII码升序排列
int main()
{
char s1[20]={"ajerucxbny"};
char s2[20]={"cbdhsykenf"};
char s[40]={};
merge(s1,s2,s);
return 0;
}
void sort(char *s)
{
int len;
len=strlen(s);
int i,j;
for (i = 0; i < len; i++)
{
for (j = i+1; j < len; j++)
{
if(s[i]>s[j])
{
char c;
c=s[i];
s[i]=s[j];
s[j]=c;
}
}
}
}
void merge(char *s1,char *s2,char *s)
{
int i,j,k,n;
strcpy(s,s1);
strcat(s,s2);
sort(s);
for (n = 0; s[n] != '\0'; n++);/*用于得到字符串长度，也可以使用n=strlen(s);*/
for (i = 0; i < n ; i++)
{
for (j = k = i + 1; j < n ; j++)
if (s[j] != s[i])
s[k++] = s[j];
s[k] = '\0';
}
printf("合并后的字符串为:\n");
puts(s);
}```

• 静夜思2020-06-12 20:45 送鲜花  1朵   附言：问题解决以后分享出来，所有新人
• 6
• 1/1页
• 1