Advertisement
Guest User

Untitled

a guest
Oct 1st, 2021
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.List;
  6. import java.util.Scanner;
  7.  
  8. public class Anagram {
  9. public static void main(String[] args) {
  10. Scanner scanner = new Scanner(System.in);
  11.  
  12. String input = scanner.nextLine();
  13. int countOfWords = Integer.parseInt(scanner.nextLine());
  14. List<String> wordsToTry = new ArrayList<>();
  15. for (int i = 1; i <= countOfWords; i++) {
  16. String word = scanner.nextLine();
  17. wordsToTry.add(word);
  18. }
  19. for (int i = 0; i < wordsToTry.size() ; i++) {
  20. char[] inputarr = input.toCharArray();
  21. char[] word = wordsToTry.get(i).toCharArray();
  22.  
  23. Arrays.sort(inputarr);
  24. Arrays.sort(word);
  25.  
  26. if (inputarr.length == word.length) {
  27. if (inputarr[i] == word[i]) {
  28. System.out.println("Yes");
  29. }
  30. } else {
  31. System.out.println("No");
  32. }
  33. }
  34.  
  35.  
  36. }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement