Each army fighting the world war Z is denoted with a word consisting any combination of 26 alphabets. An army is a match for his/her opponent if and only if his name is an anagram of his/her opponent. Your job as a programmer is to help find whether two randomly selected members are match for each other or not.
(An anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once. Your task is to find whether a given pair of words is anagrams to each other.
Eg: Silent is anagram to listen.)
Input:
Number of test cases (t ≤ 10). Each test case consists of a pair of strings (length of string ≤ 1000) separated by a single space.
Output:
For each test case, print ‘Yes’ if they are a match to each other and ‘No’ otherwise.
SAMPLE INPUT
2
listen silent
mancap pacmaan
SAMPLE OUTPUT
Yes
No
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We need to write a solution for the problem: Given two strings, determine if they are anagrams. Input: number of test cases t (≤10). Each test case: two strings separated by a space. Output "Yes" if anagrams else "No". Sample: 2 test cases: "listen silent" -> Yes, "mancap pacmaan" -> No. Strings length ≤1000, characters are any combination of 26 alphabets, i.e., presumably only letters? The problem says "consisting any combination of 26 alphabets", so maybe only alphabetic characters (uppercase/lowercase?). Sample uses lower case. We'll treat as case-sensitive? Usually anagram problems consider case-insensitive? But the problem statement: "word consisting any combination of 26 alphabets." It may mean the 26 English letters; case may not be specified. Usually they mean letters (a-z). We'll assume case matters? But "listen" and "silent" both lowercase; "mancap" and "pacmaan" are lowercase. Could there be uppercase? Possibly not. To be safe, we could convert to lower case or just compare as is. Since it says "26 alphabets", likely only letters, maybe both cases? Could include uppercase. For anagram, typically we ignore case but not always. The sample doesn't clarify. Usually competitive problems with anagrams treat case-insensitive? I'll check typical problems: "Anagram" often treat as case-insensitive, but some treat as is. The statement: "word consisting any combination of 26 alphabets." That suggests only letters, but not case. Could be both uppercase and lowercase as distinct? Most simple anagram problems treat as case-insensitive, but the sample uses only lowercase. I think we can treat as case-insensitive to be safe. However the problem might expect exact matching, i.e., characters exactly same including case. Since they didn't specify to ignore case, typical approach: compare sorted strings or count frequencies. Because length ≤1000, sorting each (O(n log n)) is fine for t≤10. Counting frequencies using array of 26 is also fine, but need to consider case? If only letters, we can map to 0-25 ignoring case. We'll do case-insensitive by converting to lower case. But is there any scenario with spaces? It says "word consisting any combination of 26 alphabets." So each string is a word with only alphabets, no spaces. Input format: each test case consists of a pair of strings separated by a single space. So the strings themselves don't contain spaces. So we can read two tokens.
Thus algorithm: read integer t, loop t times: read two strings s1, s2. If lengths differ, output "No". Else, either sort both and compare, or use frequency array. I'll use frequency array for efficiency: create array freq[26] = {0}; for each char in s1, increment freq[tolower(ch)-'a']; for each char in s2, decrement; after that check if all zeros.
Edge cases: strings may contain uppercase letters; tolower works. But what if non-alphabetic? Problem says only alphabets, so fine.
Now code in C, C++, Java, Python? The user didn't specify language. As ChatGPT, I need to produce a solution; but likely they want code. The instruction: "Your job as a programmer is to help find whether two randomly selected members are match for each other or not." So we need to provide a solution, perhaps in C/C++? Usually such problems are solved in multiple languages. But I'll provide a solution in Python as it's simple. But the problem may be from a platform that expects C/C++? I'll include a Python solution.
Let's write a solution:
def are_anagrams(s1, s2):
if len(s1) != len(s2):
return False
freq = [0]*26
for ch in s1.lower():
freq[ord(ch)-97] += 1
for ch in s2.lower():
idx = ord(ch)-97
freq[idx] -= 1
if freq[idx] < 0:
return False
# Actually after loop, all should be zero; but we already check negative; also need to ensure no positive? If lengths equal and no negative, sum zero ensures all zero. So return True.
return True
But careful: If we convert to lower, it's okay. But ensure that ch is always a letter. Since input guaranteed to be letters, fine.
Read t, then for each line, split into two strings. There might be leading/trailing spaces. Use input().split().
Now produce final answer.
But the user may want explanation. The instruction: "You are ChatGPT, large language model trained ..." The user likely wants the solution. So we will output a code block.
We'll also include brief explanation.
Now I'll respond accordingly. To solve the problem, we need to check if two given strings are anagrams of each other. An anagram means both strings have the same characters with the same frequencies (ignoring case, as typical). The constraints are small (t ≤ 10, length ≤ 1000), so we can use a simple frequency array of size 26.
Approach
Read the number of test cases t.
For each test case, read two strings a and b.
If lengths differ, print No immediately.
Otherwise, create a frequency array of 26 integers initialized to 0.
Convert both strings to lowercase (since only English letters are used).
For each character in a, increment the corresponding index.
For each character in b, decrement the corresponding index; if any count becomes negative, they are not anagrams.
After processing both strings, if no negative occurred and lengths were equal, print Yes; else No.
Complexity
Time: O(n) per test case, where n is the length of the strings.
Space: O(1) extra space (array of size 26).
Sample Input/Output
code
Input:
2
listen silent
mancap pacmaan
Output:
Yes
No
Here is a Python implementation:
python
import sys
def is_anagram(s1: str, s2: str) -> bool:
if len(s1) != len(s2):
return False
freq = [0] * 26
for ch in s1.lower():
freq[ord(ch) - ord('a')] += 1
for ch in s2.lower():
idx = ord(ch) - ord('a')
freq[idx] -= 1
if freq[idx] < 0:
return False
return True
def main():
data = sys.stdin.read().strip().split()
if not data:
return
t = int(data[0])
out = []
idx = 1
for _ in range(t):
if idx + 1 >= len(data):
break
a = data[idx]
b = data[idx + 1]
idx += 2
out.append("Yes" if is_anagram(a, b) else "No")
sys.stdout.write("\n".join(out))
if __name__ == "__main__":
main()
This code reads all input at once, processes each test case, and prints the result. It works for the given constraints and is efficient.