View Code of Problem 22

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

Double click to view unformatted code.


Back to problem 22