View Code of Problem 22

#include <bits/stdc++.h>
using namespace std;
int main(){
	string s1,s2;
	while(cin>>s1){
		cin>>s2;
		int h1[128]={0},h2[128]={0};
		for(int i=0;i<s1.size();i++)
			h1[s1[i]]++;
		for(int i=0;i<s2.size();i++)
			h2[s2[i]]++;
		for(int i=0;i<128;i++){
			if(h1[i]&&h2[i]){
				cout<<(char)i;
				h1[i]--;
				h2[i]--;
				i--;
			}
		}
		cout<<endl;
	}
} 

Double click to view unformatted code.


Back to problem 22