View Code of Problem 22

#include <stdio.h>
#include <string.h>
int main(){
	char a[1500]={'\0'},b[1500]={'\0'};
	while(gets(a)!=NULL&&gets(b)!=NULL){
		int num[26]={0},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");
	}
}

Double click to view unformatted code.


Back to problem 22