View Code of Problem 22

#include <stdio.h>
#include <string.h> 
int main (void)
{
	char a[1000],b[1000];
	char c[1000];
	int len1,len2;
	int t,i,j;
	char temp;
	while(gets(a)!=NULL&&gets(b)!=NULL){
		len1=strlen(a);
		len2=strlen(b);
		t=0;
		for(i=0;i<len1;i++){
			for(j=0;j<len2;j++){
					if(a[i]==b[j]){
					c[t++]=b[j];
					b[j]=' ';
					break;
					}
				}	
			}
		for(i=0;i<t-1;i++){
			for(j=i+1;j<t;j++){
				if(c[i]>c[j]){
					temp=c[i];
					c[i]=c[j];
					c[j]=temp;	
				}
			}
		}
		for(i=0;i<t;i++){
			printf("%c",c[i]);
		}
		printf("\n");
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 22