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