View Code of Problem 22

#include <stdio.h>
#include <string.h>
int main()
{
	char str1[1000],str2[1000];
	int l1,l2;
	int i,j;
	while(gets(str1)!=NULL && gets(str2)!=NULL)
	{
		int k[26]={0};
		l1=strlen(str1);
		l2=strlen(str2);
		for(i=0;i<l1;i++)
		{
			for(j=0;j<l2;j++)
			{
				if(str1[i]==str2[j])
				{
					k[str1[i]-'a']++;
					str2[j]='0';
					break;
				}
			}
		}
		for(i=0;i<26;i++)
		{
			for(j=k[i];j>0;j--)
			{
				printf("%c",i+'a');
			}
		}
		printf("\n");
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 22