Guest User

Untitled

a guest
Jun 14th, 2021
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class WordAnagrams {
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.         String input = sc.nextLine();
  10.         char[] inputChar = input.toCharArray();
  11.         int n = Integer.parseInt(sc.nextLine());
  12.  
  13.         for (int i = 0; i < n; i++) {
  14.             String words = sc.nextLine();
  15.             char[] letterwords = words.toCharArray();
  16.             Arrays.sort(inputChar);
  17.             Arrays.sort(letterwords);
  18.             if (inputChar.length == letterwords.length) {
  19.                 if (inputChar[i] == letterwords[i]) {
  20.                     System.out.println("Yes");
  21.                 }
  22.             }
  23.             else {
  24.                 System.out.println("No");
  25.             }
  26.  
  27.  
  28.         }
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment