View Code of Problem 22

#include<stdio.h>
#include<string.h>

void norepeat(char ch[],int n)
{
	int i,j,k;
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(ch[i] == ch[j])
			{
				for(k=j;k<n;k++)
				{
					ch[k] = ch[k+1];
				}
				n--;
				j--;
			}
		}
	}
}
void sort (char ch[],int n)
{
	int i,j;
	char t;
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(ch[i]>ch[j])
			{
				t = ch[i];
				ch[i] = ch[j];
				ch[j] = t;
			}
		}
	}
}

int main()
{
	char str1[2000],str2[2000],ch[2000];
	while( gets(str1)!=NULL)
	{
		gets(str2);
		int i,j,m,n;
		int k = 0;
		n = strlen(str1);
		m = strlen(str2);
		for(i=0;i<n;i++)
		{
			for(j=0;j<m;j++)
			{
				if( str1[i] == str2[j] )
				{
					ch[k] = str1[i];
					k++;
				}
			}
		}
		int q = strlen(ch);
		norepeat(ch,q);
		int w = strlen(ch);
		sort(ch,w);
		puts(ch);
	//	printf("\n");		
	}
	return 0;
}





Double click to view unformatted code.


Back to problem 22