View Code of Problem 22

#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a,b;
	while(getline(cin,a))
	{
		getline(cin,b);
		char h[1000],k=0;
		for(int i=0;i<a.length();i++)
		{
			for(int j=0;j<b.length();j++)
			{
				if(a[i]==b[j])
				{
				h[k]=a[i];
				k++;
				b[j]='#';
				break;
				}
			}
		 } 
		 sort(h,h+k);
		 for(int i=0;i<k;i++)
		 {
		 	cout<<h[i];
		 }
		 cout<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 22