View Code of Problem 22

#include<bits/stdc++.h>
using namespace std;
int fun(int x,int y){
	return x<y?x:y;
}
int main(){
	int word1[28],word2[28];
	string s1,s2;
	while(getline(cin,s1)&&getline(cin,s2)){
		memset(word1,0,sizeof(word1));
		memset(word2,0,sizeof(word2));
		for(int i=0;i<s1.size();++i){
			word1[s1[i]-'a']++;
		}
		for(int i=0;i<s2.size();++i){
			word2[s2[i]-'a']++;
		}
		for(int i=0;i<26;++i){
			if(word1[i]!=0&&word2[i]!=0)
			for(int k=0;k<fun(word1[i],word2[i]);k++)
			printf("%c",'a'+i);
		}
		cout<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 22