View Code of Problem 22

#include<stdio.h>
#include<string.h>
#define N 1000
int main(){
	char x[N];
	char y[N];
	char a[N];
	int i,j;
	char temp;
	while(gets(x)!='\0'){
		gets(y);
		int t=0;
		int n=strlen(x);
		int m=strlen(y);
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				if(x[i]==y[j]){
					a[t++]=y[j];
					y[j]='\0';
					break;
				}
			}
		}
		a[t]='\0';
		for(i=0;i<t;i++){
			for(j=0;j<t;j++){
				if(a[i]<a[j]){
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				} 
			}
		}
		for(i=0;i<t;i++){
		printf("%c",a[i]);
	}
	}
	printf("\n");
	return 0;	
}

Double click to view unformatted code.


Back to problem 22