HJ81 字符串字符匹配
法一
import java.util.*;
public class Main {
public Main() {
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Main solution = new Main();
while (sc.hasNext()) {
String pShort = sc.nextLine();
String pLong = sc.nextLine();
System.out.println(solution.isAllCharExist(pShort, pLong));
}
}
public boolean isAllCharExist(String pShort, String pLong) {
Set<Character> set = new HashSet<>();
for (char ch : pLong.toCharArray()) {
set.add(ch);
}
for (char ch : pShort.toCharArray()) {
if (!set.contains(ch)) {
return false;
}
}
return true;
}
}
法二
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextLine()) {
String a = scanner.nextLine();
String b = scanner.nextLine();
String[] arr = a.split(" ");
int count = 0;
for (int i = 0 ; i < arr.length ; i++ ) {
if (b.contains(arr[i])) {
count++;
}
}
if (count == arr.length) {
System.out.println(true);
} else {
System.out.println(false);
}
}
}
}