#C2660. Anagram Rearrangement
Anagram Rearrangement
Anagram Rearrangement
You are given two strings A and B. Your task is to determine whether A can be rearranged to form B (i.e. whether B is an anagram of A).
Specifically, given two strings, check if by reordering the characters of A you can obtain exactly the string B. Formally, if we denote by \( sort(\cdot) \) the operation that sorts the characters of a string in non-decreasing order, then we require that:
[ sort(A) = sort(B) ]
If this condition holds, output YES
; otherwise, output NO
.
inputFormat
The input is given from standard input and has the following format:
- The first line contains an integer T (\(1 \le T \le 10^4\)), the number of test cases.
- For each test case, there are exactly two lines:
- The first line contains the string A.
- The second line contains the string B.
Note that the strings may be empty.
outputFormat
For each test case, print a single line containing YES
if the string A can be rearranged to form B, or NO
otherwise. The answers for the test cases should appear in the order in which the test cases are given.
5
anagram
nagaram
rat
car
listen
silent
aabbcc
abc
testcase
testcase
YES
NO
YES
NO
YES
</p>