View Code of Problem 22

#include<string.h>
#include<math.h>
#include<stdio.h>
#include<ctype.h>
int main()
{
	char a[1010],b[1010];
	while(gets(a)!=NULL)
	{
		gets(b);
		char c[1010]={'\0'};
		int i,j,k=0;
		for(i=0;i<strlen(a);i++)
		{
			for(j=0;j<strlen(b);j++)
			{
				if(a[i]==b[j])
				{
					c[k++]=a[i];
					b[j]='*';
					break;
				}
			}
		}
		for(i=0;i<k;i++)
		{
			char t; 
			for(j=0;j<k;j++)
			{
				if(c[j]>c[i])
				{
					t=c[i];
					c[i]=c[j];
					c[j]=t;
				}
			}
		}
		/*printf("%c",c[0]);
		for(i=1;i<k;i++)
		{
			if(c[i]==c[i-1]) continue;
			else printf("%c",c[i]);
		 } 
		 printf("\n");*/
		 puts(c); 
	}
	return 0;
 } 

Double click to view unformatted code.


Back to problem 22