利用 HashSet 解决
import java.util.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意这里的 hasNext 和 hasNextLine
while (in.hasNext()) {
// 短串
String S = in.nextLine();
// 长串
String T = in.nextLine();
// 遍历短串,然后把他们都装入 set
char[] Schars = S.toCharArray();
HashSet<Character> set = new HashSet<>();
for (char c : Schars) {
set.add(c);
}
// 遍历长串,把他们都取出来
char[] Tchars = T.toCharArray();
for (char c : Tchars) {
set.remove(c);
}
// 如果为空说明短串里面的都被取出来了,都在长串里
System.out.println(set.isEmpty());
}
}
}

京公网安备 11010502036488号