下面程序的功能是从键盘上输入两个字符串,对两个字符串分别排序;然后将它们合并,合并后的字符串按ASCII码值从小到大排序,并删去相同的字符。 #include
strmerge(a,b,c) /* 将已排好序的字符串a、b合并到c */ char *a,*b,*c; { char t,*w; w=c; while( *a!= '\0' 1 *b!='\0' ) { t= 2 ?*a++:*b<*a ? *b++ : ( 3 ); /* 将*a、*b的小者存入t */ if( *w 4 '\0' ) *w=t; else if( t 5 *w) *++w=t; /* 将与*w不相同的t存入w */ } while( *a != '\0' ) /* 以下将a或b中剩下的字符存入w */ if( *a != *w ) *++w=*a++; else a++; while( *b != '\0') if( *b != *w ) *++w=*b++; else b++; *++w = 6 ; } strsort( char *s ) /* 将字符串s中的字符排序 */ { int i,j,n; char t,*w; 7 ; for( n=0;*w != '\0'; 8 ) w++; for( i=0;i
s[j] ) { 9; 10; 11 ; } } main( ) { char s1[100],s2[100],s3[200]; printf("\nPlease Input First String:"); scanf("%s",s1); printf("\nPlease Input Second String:"); scanf("%s",s2); strsort(s1); strsort(s2); 12 = '\0'; strmerge(s1,s2,s3); printf("\nResult:%s",s3); }