UVA 10252 Java

  1. import java.util.*;
  2.  
  3. public class main{
  4. public static void main(String[] args) {
  5. Scanner sc=new Scanner(System.in);
  6. while(sc.hasNextLine())
  7. {
  8. String str1 = sc.nextLine().toLowerCase();
  9. String str2 = sc.nextLine().toLowerCase();
  10. int[] count1 = new int[26];
  11. int[] count2 = new int[26];
  12. for(int i = 0; i < str1.length(); i++)
  13. {
  14. char c = str1.charAt(i);
  15. if(c>='a' && c <= 'z')
  16. count1[c - 'a']++;
  17. }
  18. for(int i = 0; i < str2.length(); i++)
  19. {
  20. char c = str2.charAt(i);
  21. if(c >= 'a' && c <= 'z')
  22. count2[c - 'a']++;
  23. }
  24. for(int i = 0; i < 26; i++)
  25. if(count1[i] != 0 && count2[i] != 0)
  26. {
  27. int min = Math.min(count1[i], count2[i]);
  28. for(int j = 0; j < min; j++)
  29. System.out.print((char)(i + 'a'));
  30. }
  31. System.out.println();
  32. }
  33. }
  34. };
  35.  

留言

這個網誌中的熱門文章

C# 井字遊戲