Sphere Online Judge

SPOJ Problem Set (classical)

1728. Common Permutation

Problem code: CPRMT

Given two strings of lowercase letters, a and b, print the longest string x of lowercase letters such that there is a permutation of x that is a subsequence of a and there is a permutation of x that is a subsequence of b.

Input

Input file contains several lines of input. Consecutive two lines make a set of input. That means in the input file line 1 and 2 is a set of input, line 3 and 4 is a set of input and so on. The first line of a pair contains a and the second contains b. Each string is on a separate line and consists of at most 1000 lowercase letters.

Output

For each set of input, output a line containing x. If several x satisfy the criteria above, choose the first one in alphabetical order.

Example

Sample input:
pretty
women
walking
down
the
street
 
Sample output:
e
nw
et 

Added by:Andrés Leonardo Rojas Duarte
Date:2007-08-05
Time limit:1s
Source limit:50000B
Memory limit:256MB
Cluster: Pyramid (Intel Pentium III 733 MHz)
Languages:All except: ERL JS NODEJS PERL 6
Resource:University of Alberta Local Contest 1999

hide comments
2013-05-10 11:06:36 rahul kumar singh
what if there z no x?wat will it print in that case??
2013-03-22 11:07:16 Ouditchya Sinha
Nice Problem... :)
I used while( scanf("%s\n%s",in1,in2) != EOF );

Last edit: 2013-03-22 11:07:30
2013-02-06 15:14:31 adrises
how many test cases are to be taken
2013-01-28 06:32:37 vijay
print o/p in sorted order otherwise you got WA.
2012-12-22 17:57:25 Abhimanyu
facing wrong answer .... please give some suggestions ..
2012-08-10 04:36:32 Simón Murillo Gómez
Easy!
2012-07-19 19:50:59 omar alkattan
finally AC
thanks @The_Godfather example is very important
thanks @Noszály Csaba too
2012-07-06 20:13:14 PANKAJ SAINI
more test cases please,, for these, my code works fine and for other so many too...

2012-07-03 18:21:22 Sabarinath
very easy indeed!!
2012-06-23 05:52:41 PANKAJ SAINI
I am getting right answer for the test cases and few i checked myself...
but still getting WA

help..
SPOJ © 2013 Sphere Research Labs. All Rights Reserved.