View Code of Problem 22

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

Double click to view unformatted code.


Back to problem 22