#C6985. Rearrangement to Form String
Rearrangement to Form String
Rearrangement to Form String
Given two strings S and T, determine whether T can be obtained by rearranging the letters of S. In other words, check if the multiset of characters in S is exactly the same as that in T.
If they match exactly, output YES
; otherwise, output NO
.
Note that the order of characters does not matter, only the frequency of each character.
You are required to read the input from stdin and print the output to stdout.
Mathematically, if we denote by \( f_S(x) \) and \( f_T(x) \) the frequency of letter \( x \) in S and T respectively, then the answer is "YES" if and only if \( f_S(x) = f_T(x) \) for every letter \( x \) in the alphabet, and "NO" otherwise.
inputFormat
The first line of input contains a single integer \( T \) representing the number of test cases.
Each of the following \( T \) lines contains two space-separated strings \( S \) and \( T \).
For each test case, you need to determine if string T can be formed by rearranging the letters of string S.
outputFormat
For each test case, print a single line with the answer: YES
if T can be formed by rearranging S, and NO
otherwise.
3
ABACUS CASUBA
HELLO OLEHL
WORLD WORD
YES
YES
NO
</p>