Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class WordAnagrams {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String word = scanner.nextLine();
- int num = Integer.parseInt(scanner.nextLine());
- for (int i = 0; i < num; i++) {
- String[]anagram = scanner.nextLine().split("");
- if (anagram.length == word.length()) {
- List<String> wordChars = Arrays.stream(word.split("")).collect(Collectors.toList());
- for (int j = 0; j < anagram.length; j++) {
- wordChars.remove(anagram[j]);
- }
- if (wordChars.isEmpty()) {
- System.out.println("Yes");
- } else {
- System.out.println("No");
- }
- } else {
- System.out.println("No");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement