View Code of Problem 22

#include<stdio.h>

int main() {
	char arr1[1000];
	char arr2[1000];
	while (gets(arr1) != NULL&& gets(arr2)!=NULL) {
		int len1 = strlen(arr1);
		int len2 = strlen(arr2);
		int n[26] = { 0 };
		for (int i = 0; i < len1; i++)
		{
			for (int j = 0; j < len2; j++)
			{
				if (arr1[i]==arr2[j])
				{
					arr2[j] = '0';
					n[arr1[i]-'a']++;
					break;
				}
			}
		}
		for (int i = 0; i < 26; i++)
		{
			while (n[i]>0)
			{
				printf("%c",'a'+i);
				n[i]--;
			}
		}
		printf("\n");

	}
	return 0;
}

Double click to view unformatted code.


Back to problem 22