Created
December 22, 2015 02:00
-
-
Save peter279k/4121ec38bc3395c1a8cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class main{ | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
while(input.hasNext()) { | |
String str = input.next(); | |
String str2 = input.next(); | |
String result = ""; | |
ArrayList<String> res = new ArrayList<String>(); | |
for(int i=0;i<str.length();i++) { | |
for(int j=0;j<str2.length();j++) { | |
int count = get_list_count(res, String.valueOf((str.charAt(i)))); | |
int count2 = get_str_count(str, str2, String.valueOf((str.charAt(i)))); | |
if(count == count2) | |
continue; | |
else { | |
if(str.charAt(i) == str2.charAt(j)) | |
res.add(String.valueOf(str.charAt(i))); | |
} | |
} | |
} | |
Collections.sort(res); | |
for(int i=0;i<res.size();i++) { | |
result += res.get(i); | |
} | |
System.out.println(result); | |
} | |
} | |
public static int get_list_count(ArrayList<String> res, String str) { | |
int count = 0; | |
for(int i=0;i<res.size();i++) { | |
if(res.get(i).equals(str)) { | |
count += 1; | |
} | |
} | |
return count; | |
} | |
public static int get_str_count(String str, String str2, String char_str) { | |
int count = 0; | |
int count2 = 0; | |
for(int i=0;i<str.length();i++) { | |
if(String.valueOf(str.charAt(i)).equals(char_str)) | |
count += 1; | |
} | |
for(int i=0;i<str2.length();i++) { | |
if(String.valueOf(str2.charAt(i)).equals(char_str)) | |
count2 += 1; | |
} | |
return Math.min(count, count2); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment