import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
/**
* @param args
* @throws IOException
* UVA 10252 - Common permutation solution
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sbr = new StringBuffer("");
String m;
while ((m=bReader.readLine())!=null) {
int [] c1 = new int[26];
int [] c2 = new int[26];
int [] cres = new int[26];
for (int i=0 ; i< m.length(); i++) {
if(m.charAt(i)>='a' && m.charAt(i)<='z' ){
c1[m.charAt(i)-97]++;
}
}
m=bReader.readLine();
for (int i=0 ; i< m.length(); i++) {
if(m.charAt(i)>='a' && m.charAt(i)<='z' ){
c2[m.charAt(i)-97]++;
}
}
for (int i=0 ;i<26;i++) {
int j = Math.min(c1[i],c2[i]);
for(int m1 =0; m1<j;m1++){
sbr.append((char)(97+i));
}
}
sbr.append("\n");
}
System.out.print(sbr);
}
}
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
/**
* @param args
* @throws IOException
* UVA 10252 - Common permutation solution
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sbr = new StringBuffer("");
String m;
while ((m=bReader.readLine())!=null) {
int [] c1 = new int[26];
int [] c2 = new int[26];
int [] cres = new int[26];
for (int i=0 ; i< m.length(); i++) {
if(m.charAt(i)>='a' && m.charAt(i)<='z' ){
c1[m.charAt(i)-97]++;
}
}
m=bReader.readLine();
for (int i=0 ; i< m.length(); i++) {
if(m.charAt(i)>='a' && m.charAt(i)<='z' ){
c2[m.charAt(i)-97]++;
}
}
for (int i=0 ;i<26;i++) {
int j = Math.min(c1[i],c2[i]);
for(int m1 =0; m1<j;m1++){
sbr.append((char)(97+i));
}
}
sbr.append("\n");
}
System.out.print(sbr);
}
}
No comments :
Post a Comment