View Code of Problem 22

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

int main(){
	int i,j,k,len1,len2;
	char str1[100],str2[100],x[100],y[100],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++]=str1[i];
	  for  (i=0;i<k-1;i++)
         for (j=k-1;j>i;j--)
			 if (x[j]<x[j-1])
			 {  t=x[j];x[j]=x[j-1];x[j-1]=t;} //冒泡;
    y[0]=x[0];
	 for  (j=i=1;i<k-1;i++)
		 if (x[i]!=x[i-1])
		     y[j++]=x[i];
	
	   for (i=0;i<j-1;i++)
		   printf("%c",x[i]);
	       printf("%c\n",x[i]);

	}
	return 0;
}

Double click to view unformatted code.


Back to problem 22