Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- public class Anagram {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- int countOfWords = Integer.parseInt(scanner.nextLine());
- List<String> wordsToTry = new ArrayList<>();
- for (int i = 1; i <= countOfWords; i++) {
- String word = scanner.nextLine();
- wordsToTry.add(word);
- }
- for (int i = 0; i < wordsToTry.size() ; i++) {
- char[] inputarr = input.toCharArray();
- char[] word = wordsToTry.get(i).toCharArray();
- Arrays.sort(inputarr);
- Arrays.sort(word);
- if (inputarr.length == word.length) {
- if (inputarr[i] == word[i]) {
- System.out.println("Yes");
- }
- } else {
- System.out.println("No");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement