View Code of Problem 22

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

Double click to view unformatted code.


Back to problem 22