用Set走捷径!把短字符串的字符加入到Set中,把长字符的字符从Set中剔除,如果最后Set为空,则满足条件。
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
String shortstr = in.nextLine();
String longstr = in.nextLine();
Set<Character> set = new HashSet<>();
for(int i=0;i<shortstr.length();++i){
set.add(shortstr.charAt(i));
}
for(int i=0;i<longstr.length();++i){
set.remove(longstr.charAt(i));
}
System.out.println(set.size()==0);
}
}
}