View Code of Problem 22

#include<stdio.h>
#include<string.h>
int main()
{
	char a[1000], b[1000];
	while (gets(a))
	{
		gets(b);
		int lena = strlen(a);
		int lenb = strlen(b);
		char s[1000];
		int k = 0;
		for (int i = 0; i < lena;i++ )
		{
			for (int j = 0; j < lenb;j++ )
			{
				if (a[i] == b[j])
				{
					s[k++] = a[i];
					b[j] = '*';
					break;
				}
			}
		}
		for (int i = 0; i < k; i++)
		{
			for (int j = i+1; j < k; j++)
			{
				if (s[i] > s[j])
				{
					char t = s[i];
					s[i] = s[j];
					s[j] = t;
				}
			}
		}
		for (int i = 0; i < k; i++)
		{
			printf("%c", s[i]);
		}
		printf("\n");
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 22