View Code of Problem 22

   #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	char a[1005],b[1005];
    	while(scanf("%s%s",a,b)!=EOF){
    		int aa[30] = { },bb[30] = { };
    		for(int i = 0;i<strlen(a);i++){
    			aa[a[i]-'a'+1]++;
    		}
    		for(int i = 0;i<strlen(b);i++){
    			bb[b[i]-'a'+1]++;
    		}
    		for(int i = 1;i<27;i++){
    			while(aa[i] && bb[i]){
    				cout<<(char)(i+'a'-1);
    				aa[i]--;
					bb[i]--;
    			}
    		}
    		cout<<endl;
    		a[0] = '\0';
    		b[0] = '\0'; 
    	}
    	return 0;
    }

Double click to view unformatted code.


Back to problem 22