#C11021. Check if Word Pairs are Anagrams
Check if Word Pairs are Anagrams
Check if Word Pairs are Anagrams
You are given a list of N
words and M
queries. Each query consists of two integers i and j (with $1 \le i, j \le N$). For each query, determine whether the i-th word is an anagram of the j-th word.
An anagram is a word formed by rearranging the letters of another, using all the original letters exactly once.
Input/Output Example:
Input: 4 listen silent rock cork 3 1 2 3 4 1 3</p>Output: True True False
Your task is to implement a solution that reads from standard input and writes to standard output.
inputFormat
The input is given via standard input and consists of the following:
- An integer
N
representing the number of words. - A line with
N
words separated by spaces. - An integer
M
representing the number of queries. M
lines, each containing two space-separated integers i and j (1-based indices) representing a query.
outputFormat
For each of the M
queries, output True
if the two words are anagrams of each other, and False
otherwise. Each output should be printed on a new line.
4
listen silent rock cork
3
1 2
3 4
1 3
True
True
False
</p>