View Code of Problem 22

#include<stdio.h>
#include<string.h>

int main(){
	int i,j,k,len1,len2;
	char str1[1000],str2[1000],x[1000],t;
	while(gets(str1))
	{
	   gets(str2);
	   len1=strlen(str1);
	   len2=strlen(str2);
	   for (k=i=0;i<len1;i++)
	   {
		   for (j=0;j<len2;j++)
			   if (str1[i]==str2[j])
			   {
				   x[k++]=str2[j];
				   str2[j]='1';
				   break;
			   }
	   }
	  x[k]='\0';
	  for  (i=0;i<k;i++)
         for (j=i;j<k;j++)
			 if (x[j]<x[i])
			 {  t=x[j];x[j]=x[i];x[i]=t;} //冒泡;
     puts(x);
	 /*  for (i=0;i<k-1;i++)
		   printf("%c",x[i]);
	       printf("%c\n",x[k-1]);
*/
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 22