2013
11-11

# Common permutation

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 consists of pairs of lines. 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 1,000 lowercase letters.

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

pretty
women
walking
down
the
street


e
nw
et



//* @author  [email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
String s=""; int[] l1,l2;
l1=new int[26];l2=new int[26];
for(int i=0;i< s.length();i++){
l1[(int)(s.charAt(i)-'a')]++;
}
for(int i=0;i< s.length();i++){
l2[(int)(s.charAt(i)-'a')]++;
}
for(int i=0;i< 26;i++){
l1[i]=Math.min(l1[i], l2[i]);
}
for(int i=0;i< 26;i++){
for(int j=0;j< l1[i];j++){
System.out.print((char)(i+'a'));
}
}
System.out.print("\n");
}
}
}

1. Excellent Web-site! I required to ask if I might webpages and use a component of the net web website and use a number of factors for just about any faculty process. Please notify me through email regardless of whether that would be excellent. Many thanks