View Code of Problem 22

#include <stdio.h>
#include <string.h>
#define N 1001
int main()
{
	char a[N], b[N];
	char c[N];
	int i, j;
	char temp;
	while(gets(a) != NULL)
	{
		gets(b);
		int t = 0;
		int n = strlen(a);
		int m = strlen(b);
		for(i = 0; i < n; i++)
		{
			for(j = 0; j < m; j++)
			{
			    if(a[i] == b[j])
				{
				    c[t++] = a[i];
				}
			}
		}
		c[t] = '\0';
		for(i = 0; i < t; i++)
		{
			for(j = 0; j < t; j++)
			{
				if(i != j&&c[i] != '0')
				{
					if(c[i] == c[j])
					{
						c[j] = '0';
					}
				}
			}
		}
		for(i = 0; i < t; i++)
		{
			for(j = i; j < t; j++)
			{
				if(c[i] > c[j])
				{
					temp = c[i];
					c[i] = c[j];
					c[j] = temp;
				}
			}
		}
		for(i = 0; i < t; i++)
		{
			if(c[i] != '0')
			{
				printf("%c", c[i]);
			}
		}
		printf("\n");
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 22