import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { // 输入数据 Scanner in = new Scanner(System.in); String shortStr = in.nextLine(); String longStr = in.nextLine(); // 算法核心 // 注意!虽然Character是对象,但是作为基本类型的包装类,在map中的主键依旧是“字面值哈希”而非“地址(引用)值哈希” // 1.遍历longStr,将其所有出现的字符登记其出现次数 HashMap<Character, Integer> map = new HashMap<>(); for (int i = 0; i < longStr.length(); i++) { char c = longStr.charAt(i); int count = 1; if (map.containsKey(c)) { count += map.get(c); } map.put(c, count); } // 2.遍历shortStr,一旦发现某个字符不在map中,就报错 boolean flag = true; for (int i = 0; i < shortStr.length(); i++) { char c = shortStr.charAt(i); if (!map.containsKey(c)) { flag = false; break; } } // 输出结果 System.out.println(flag ? "true" : "false"); } }