Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class WordAnagrams {
- public static void main(String[] args) {
- Scanner myScan=new Scanner(System.in);
- String word=myScan.nextLine();
- int n=Integer.parseInt(myScan.nextLine());
- for (int i = 0; i < n; i++) {
- String wordCurrent=myScan.nextLine();
- boolean isAnagram=true;
- for (int j = 0; j < word.length(); j++) {
- String ch=String.valueOf(word.charAt(j));
- if (!wordCurrent.contains(ch)){
- isAnagram=false;
- break;
- }else{
- wordCurrent=wordCurrent.replaceFirst(ch,"");
- }
- }
- System.out.println(isAnagram?"Yes":"No");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment