View Code of Problem 22

#include<stdio.h>
#include<string.h>
int main()
{
    char a[1000],b[1000];
    while((gets(a)&&gets(b))!=EOF)
    {
        int len1=strlen(a);
        int len2=strlen(b);
        int i,j,k;
        k=0;
        char c[1000];
        for(i=0;i<len1;i++)
        {
        	for(j=0;j<len2;j++)
        	{
        	  if(a[i]==b[j])
			  {
			  	 c[k]=a[i];
			  	 b[j]='0';
			  	 k++;
			  	 break;
			  }	
			} 
		}
		for(i=0;i<k;i++)
		{
			for(j=i;j<k;j++)
			{
				if(c[i]>c[j])
				{
					char t;
					t=c[i];
					c[i]=c[j];
					c[j]=t;
				}
			}
		}
		c[k]='\0';
		puts(c);
    }
}

Double click to view unformatted code.


Back to problem 22