View Code of Problem 22

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

Double click to view unformatted code.


Back to problem 22