题解 | #字符串字符匹配#
字符串字符匹配
https://www.nowcoder.com/practice/22fdeb9610ef426f9505e3ab60164c93
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import static java.util.Arrays.*;
import static java.util.stream.Stream.*;
public class Main {
public static void main(String[] args) throws IOException {
//testCompletePack();
testTh();
}
private static void testTh() throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String str;
while ((str = bf.readLine()) != null) {
char[] chars = str.toCharArray();
HashSet<Character> hs = new HashSet<>();
for (int i = 0; i < chars.length; i++) {
hs.add(chars[i]);
}
str = bf.readLine();
char[] charArray = str.toCharArray();
HashSet<Character> hashSet = new HashSet<>();
for (char c : charArray) {
hashSet.add(c);
}
int flag = 0;
for (Character h : hs) {
boolean contains = hashSet.contains(h);
if (!contains) {
System.out.println(false);
flag = 1;
break;
}
}
if (flag == 0) System.out.println(true);
}
}
}
查看11道真题和解析