View Code of Problem 22

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

Double click to view unformatted code.


Back to problem 22