ACM (UVa) : 10252


#include <ctype.h>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;

int main ()
{
	char A[1015], B[1015];
	long I, Len, J;

	while (gets (A)){
	    gets (B);

	    long Alpha [30];
	    for (I = 0; I < 26; I++)
	    Alpha [I] = 0;

		Len = strlen (A);
		sort (A, A+Len);

		for (I=0; I<Len; I++)
            Alpha [(A[I]-97)]++;

		Len = strlen (B);
		sort (B, B+Len);

		for (I=0; I<Len; I++) {
            if (Alpha[(B[I]-97)]) {
                cout << B[I];
                Alpha [(B[I]-97)]--;
            }
        }

		cout << '\n';
	}
	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s