fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static int sol(String s,String t){
  11. int count = Integer.MAX_VALUE;
  12. int smp[] = new int[26];
  13. int tmp[] = new int[26];
  14. for(int i=0;i<s.length();i++){
  15. smp[s.charAt(i)-'a']++;
  16. }
  17. for(int i=0;i<t.length();i++){
  18. tmp[t.charAt(i)-'a']++;
  19. }
  20. for(char c:t.toCharArray()){
  21. if(smp[c-'a']==0) return 0;
  22. count=Math.min(count,smp[c-'a']/tmp[c-'a']);
  23. }
  24. return count;
  25.  
  26. }
  27. public static void main (String[] args) throws java.lang.Exception
  28. {
  29. // your code goes here
  30. Scanner sc = new Scanner(System.in);
  31. String s = sc.next();
  32. String t = sc.next();
  33. System.out.println(sol(s,t));
  34. }
  35. }
Success #stdin #stdout 0.1s 56516KB
stdin
abdadccacd
edac
stdout
0